You can try the below snippet
SqlConnection cn = new SqlConnection( "Data Source=SQlHS;Initial Catalog=DB;Integrated Security=True"); cn.Open(); SqlCommand cm = new SqlCommand("SELECT *FROM mytable");
cm.Connection = cn; SqlDataAdapter da = new SqlDataAdapter(cm); DataTable dt = new DataTable(); da.Fill(dt); cn.Close(); dataGridView1.DataSource = dt;
Follow these steps :-
1. Create a connection.
2. Fire the select query and fill the records in the dataset.
3. Bind the dataset with the grid.
100 views
Usually answered in minutes!
yes..VS 2003
Are you using Visual Studio? .net?
×