Main Page | Report this Page
.NET DotNet Forum Index  »  General Discussion  »  Display data on DataGridView...
Page 1 of 1    

Display data on DataGridView...

Author Message
Curious...
Posted: Wed Oct 28, 2009 8:31 am
Guest
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?
 
PvdG42...
Posted: Thu Oct 29, 2009 9:09 am
Guest
"Curious" <fir5tsight at (no spam) yahoo.com> wrote in message
news:ca849de8-4756-414c-859e-d03105d04987 at (no spam) s31g2000yqs.googlegroups.com...
Quote:
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/Search/en-US?query=ado.net%20tutorial%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.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Tue Dec 01, 2009 3:15 pm