Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Display data on DataGridView

Reply
 
Old 4 Weeks Ago   #1 (permalink)
Curious


 
 

Display data on DataGridView

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?


My System SpecsSystem Spec
Old 4 Weeks Ago   #2 (permalink)
PvdG42


 
 

Re: Display data on DataGridView


"Curious" <fir5tsight@newsgroup> wrote in message
news:ca849de8-4756-414c-859e-d03105d04987@newsgroup
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/libr...rs(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.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Microsoft Script Debugger Locals Window Doesn't display VBScript COMobject Data VB Script
HTA file - display data from DB records in table like ASP - how? VB Script
RE: Data error DataGridView DataGridViewComboBoxColumn .NET General
Data Fetching and system.windows.forms.form & .datagridview PowerShell
How do I get format-table to drop that omission points (...) and display my data PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46