PC Review


Reply
Thread Tools Rate Thread

Display data on DataGridView

 
 
Curious
Guest
Posts: n/a
 
      28th Oct 2009
I'll need to display data in a grid on a Windows Form, call it
"frmGrid". Since I cannot find "GridView" in the Toolbox, I pick
"DataGridView" instead (call it "dataGridView1"). I have the code
below:

mConnection = new SqlConnection("Data
Source=Westwind;Initial Catalog=db_dynamic_trading;Integrated
Security=True;");
mConnection.Open();

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter
("db_dynamic_trading.dbo.emily_get_records", mConnection);
da.SelectCommand.CommandType =
CommandType.StoredProcedure;
da.Fill(ds);

frmGrid fGrid = new frmGrid(da); // Call constructor
below to connect dataGridView1 with da

fGrid.Show();

In constructor for frmGrid, I have the code below to connect
dataGridView1 with da:


public frmGrid(SqlDataAdapter da)
{
InitializeComponent();

this.dataGridView1.DataSource = da;
this.dataGridView1.DataBind();
}

Now the code cannot even compile because it complains that
'System.Windows.Forms.DataGridView' does not contain a definition for
'DataBind'.

Any advice on how to get this fixed?

 
Reply With Quote
 
 
 
 
PvdG42
Guest
Posts: n/a
 
      29th Oct 2009

"Curious" <(E-Mail Removed)> wrote in message
news:ca849de8-4756-414c-859e-(E-Mail Removed)...
> I'll need to display data in a grid on a Windows Form, call it
> "frmGrid". Since I cannot find "GridView" in the Toolbox, I pick
> "DataGridView" instead (call it "dataGridView1"). I have the code
> below:
>
> mConnection = new SqlConnection("Data
> Source=Westwind;Initial Catalog=db_dynamic_trading;Integrated
> Security=True;");
> mConnection.Open();
>
> DataSet ds = new DataSet();
> SqlDataAdapter da = new SqlDataAdapter
> ("db_dynamic_trading.dbo.emily_get_records", mConnection);
> da.SelectCommand.CommandType =
> CommandType.StoredProcedure;
> da.Fill(ds);
>
> frmGrid fGrid = new frmGrid(da); // Call constructor
> below to connect dataGridView1 with da
>
> fGrid.Show();
>
> In constructor for frmGrid, I have the code below to connect
> dataGridView1 with da:
>
>
> public frmGrid(SqlDataAdapter da)
> {
> InitializeComponent();
>
> this.dataGridView1.DataSource = da;
> this.dataGridView1.DataBind();
> }
>
> Now the code cannot even compile because it complains that
> 'System.Windows.Forms.DataGridView' does not contain a definition for
> 'DataBind'.
>
> Any advice on how to get this fixed?
>


It appears that you have some basic misunderstandings about how ADO.NET
works with a WinForm(s) application.

If you use MSDN (msdn.microsoft.com) to check available methods for the
DataGridView class, you'll see that there is no DataBind method.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview_members(VS.80).aspx

Further, if you search MSDN for "DataBind method", you'll see only ASP.NET
references.

To discover the solution you want, you can either find tutorials:

http://social.msdn.microsoft.com/Sea...al%20msdn&ac=1

Or, you can create a simple data project using VS' automatic facilities and
then observe the generated code. Simply defining a data source and dragging
it to an empty form should do what you want.


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How2 use LINQ to get and display data from class in a DataGridView? SlowPoke Microsoft C# .NET 1 3rd Jun 2009 10:12 PM
How2 use LINQ to get and display data from class in a DataGridView? SlowPoke Microsoft C# .NET 0 29th May 2009 05:58 PM
HOWTO: VB.NET 2005 - DataGridView - Multirow display of a single data row Sam Malone Microsoft Dot NET Framework Forms 0 3rd Aug 2006 05:43 PM
Datagridview customize data display URGENT!!!! MSDN Microsoft Dot NET Framework Forms 1 9th May 2006 07:49 PM
using Crystal Reports to display data in my dataset correctly (display the data I selected instead of all the data in table) JK Microsoft C# .NET 1 6th Sep 2003 10:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:25 PM.