SAM J

SAM J

  • NA
  • 24
  • 24.4k

SQL Database to DataGridView in C#.Net

Mar 21 2011 2:06 PM
So far i have done the following...

SqlConnection cnn = new SqlConnection(ConfigurationSettings.AppSettings["strConnection"]);
cnn.Open();
SqlCommand scd = new SqlCommand("select query", cnn);
SqlDataAdapter sda = new SqlDataAdapter(scd);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
DataSet ds = new DataSet();
sda.Fill(ds);
bindingSource1.DataSource = ds;                      
dataGridView1.DataSource = bindingSource1;
cnn.Close();

But this code isnt much help to me.it does not display data in datagridview. I want to retrive data from 2 different tables of Database.
Are there any settings i need to do b4 using BindingSource and DataGrid view??
How can i use DataReader for the same.

Answers (4)