4
Answers

SQL Database to DataGridView in C#.Net

SAM J

SAM J

13y
2.5k
1
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)