|
-
Jun 6th, 2005, 08:00 AM
#1
Thread Starter
Member
DataGrid & DataBind()
Hi,
Why does my DataGrid do not accept DataBind?
Code:
....
string sCnx = "server=..; uid=..; pwd=..; database=..";
SqlConnection cnx = new System.Data.SqlClient.SqlConnection(sCnx);
cnx.Open();
SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.Connection = cnx;
cmd.CommandText = "GetInfo";
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = cmd;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dgTest.DataSource = procs.GetProc();
dgTest.DataBind();
The error is:
'System.Windows.Forms.DataGrid' does not contain a definition for 'DataBind'
How can I fill the DataGrid with the dataSet?
-
Jun 7th, 2005, 08:08 PM
#2
Re: DataGrid & DataBind()
are you doing web app's?
if it's in windows app's no need to put databind.
VB Code:
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dgTest.DataSource = dataset;
-
Jun 8th, 2005, 03:14 AM
#3
Thread Starter
Member
Re: DataGrid & DataBind()
Ok, thanks. No need to put DataBind...
It works without, but it shows a +, not the DataGrid. If I push the + it show me the word "Table". Finally if I click the "Table" it shows me the DataGrid. Why? How can I display directly the DataGrid?
-
Jun 8th, 2005, 09:37 PM
#4
Re: DataGrid & DataBind()
you must create a datatable to show it directly to the datagrid w/ out clicking the "+" sign.
like this one.
VB Code:
DataSet dataSet = new DataSet();
dataSet.Tables.Add(new Datatable("dt"));
dataAdapter.Fill(dataSet.Tables[0]);
dgTest.DataSource = dataset;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|