Hi Everybody
I am very new to .net technology, i am trying to fill the datagrid with the dataset my code is as follows
string
strConnectionString;strConnectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlConnection glbConn = new SqlConnection(strConnectionString);glbConn.Open();
SqlDataAdapter MyAdaptor = new SqlDataAdapter(); DataSet myDataSet = new DataSet(); SqlCommand MyCommand = new SqlCommand();MyCommand.CommandText =
"GetPartyList";MyCommand.Connection = glbConn;
MyCommand.CommandType =
CommandType.StoredProcedure;MyCommand.CommandTimeout = 300;
MyCommand.ExecuteNonQuery();
MyAdaptor.SelectCommand = MyCommand;
MyAdaptor.Fill(myDataSet);
dataGridView1.DataSource = myDataSet.DefaultViewManager;
--------------------------------------------------------------------------------------------------------------------------------------------
but at the end there is noting shown on my datagridview, plz suggest me whatz the mistake and tell me how do i fill the datagridview with the dataset. can anybody tell me what and all other things can be done with the datagridview and if you can suggest me a good turorial for learning c# i would be better.
Regards
Rajeev
ArshadPosted Jan 2, 2008, 1:42 AM
Hi rajeev.The code u have given its a bit complex.u r tying to do two way coding with ur DataGrid.You always remember one thing whenever you are using DataAdapter then you dont have to bother about open n close the Connection,DataAdapter does Automaticallyok.I am giving u This code just try it.ok
SqlConnection glbConn = ConfigurationManager.AppSettings["ConnectionString"]
SqlCommand MyCommand = new SqlCommand();
SqlDataAdapter MyAdaptor = new SqlDataAdapter(GetPartyList,glbConn);
DataSet myDataSet = new DataSet();
MyCommand.CommandType = CommandType.StoredProcedure;//you can make this line optional after that also it will work
MyCommand.Connection = glbConn; //you can make this line optional after that also it will work
MyCommand.CommandTimeout = 300; //you can make this line optional after that also it will work
MyAdaptor.Fill(myDataSet);
dataGridView1.DataSource = myDataSet;
dataGridView1.DataBind();//If you are binding the DataGrid in Windows Application Then dont write this Line.It will give the O/P
Regards
Arshad Khan