Two ways access SQL-based data:
1) Use SqlDataAdapter
SqlConnection myConnection = new SqlConnection ( "server = (local) // NetSDK; database = pubs; Trusted_Connection = yes"); SqlDataAdapter myCommand = new SqlDataAdapter ( "select * from Authors", myConnection); DataSet ds = new DataSet (); MyCommand.Fill (DS, "author"); mydatagrid.datasource = ds.tables ["author"] .defaultView; mydatagrid.databind ();
2) Use SqlDataReader
SqlConnection myConnection = new SqlConnection ( "server = (local) // NetSDK; database = pubs; Trusted_Connection = yes"); SqlCommand myCommand = new SqlCommand ( "select * from Authors", myConnection);
MyConnection.open ();
SqlDataReader Dr = mycommand.executeReader ();
MyDataGrid.datasource = DR; mydatagrid.databind ();
MyConnection.Close ();