SqlConnection conn;
SqlDataAdapter da;
SqlCommand cmd;
conn = new SqlConnection("Data Source=SWAP;Initial Catalog=Swapnil;User ID=sa;Password=************");
cmd = new SqlCommand("select * from Employee", conn);
conn.Open();
DataSet ds = new DataSet();
DataTable dt= new DataTable();
da = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
conn.Close();
da.Fill(ds);
radGridView1.DataSource = ds;
Thanks.
5 Answers, 1 is accepted
In Windows Forms applications the controls are usually bound to the data objects using the DataSource property just like you did for RadGridView. So, your approach for binding is correct.
Regards,Nikolay
the Telerik team
Thanks.
In order to make your RadGridView show data from the DataSet, you actually need to bind the grid to the DataTable that this DataSet contains, like so:
radGridView1.DataSource = ds.Tables[0];
I hope this helps. Kind regards,
Nikolay
the Telerik team
I have AutoGenerateColumns = True and AutoGenerateHierarchy = True
I am doing the below and my grid keeps just showing me "No data to display".
Any assistance would be most helpful.
DataSet dataSet =
new
DataSet();
DataTable dataTable = dataSet.Tables.Add(
"Results"
);
dataTable.Columns.Add(
"ID"
);
dataTable.Columns.Add(
"Name"
);
dataTable.Rows.Add(
"1"
,
"Jack"
);
dataTable.Rows.Add(
"2"
,
"Donna"
);
this
.batchDisplay.DataSource = dataSet.Tables[0];
This code snippet looks correct and should fill RadGridView with two rows. I tested it against the latest version of our grid components and it works as expected. I cannot think of any reason that would cause an incorrect behavior in this case. If you still experience it, please open a new support ticket and send us a sample project which demonstrates the described behavior. This will allow us to assist you further.
Regards,Nikolay
Telerik