Private void getdata (string selectcommand, string connectionstring, int flag)
{
Sqldataadapter da = new sqldataadapter (selectcommand, connectionstring );
Dataset DS = new dataset ();
Da. Fill (DS );
This. datagridview1.datasource = Ds. Tables [0]; // you need to specify a specific table Ds. Tables [0] when using dataset directly.
}
Private void getdata (string selectcommand, string connectionstring)
{
Try
{
// Create a new data adapter based on the specified query.
Sqldataadapter dataadapter = new sqldataadapter (selectcommand, connectionstring );
// Create a command builder to generate SQL update, insert, and
// Delete commands Based on selectcommand. These are used
// Update the database.
Sqlcommandbuilder commandbuilder = new sqlcommandbuilder (dataadapter );
// Populate a new data table and bind it to the bindingsource.
Datatable table = new datatable ();
// Table. locale = system. Globalization. cultureinfo. invariantculture;
// The following three rows are equivalent to the result: This. datagridview1.datasource = Ds. Tables [0];
Dataadapter. Fill (table );
Bindingsource1.datasource = table;
Datagridview1.datasource = bindingsource1;
// Resize the datagridview columns to fit the newly loaded content.
// Datagridview1.autoresizecolumns (
// Datagridviewautosizecolumnsmode. allcellsexceptheader );
// Datagridview1.show ();
Label1.text = "bingdingsource -----" + Table. Columns [5]. tostring ();
}
Catch (sqlexception)
{
MessageBox. Show ("to run this example, replace the value of the" +
"Connectionstring variable with a connection string that is" +
"Valid for your system .");
}