This is a migrated thread and some comments may be shown as answers.

How to bind dataset to Radgrid in Windows App.

5 Answers 438 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 17 Oct 2012, 10:14 AM
How to bind dataset to Radgrid in Windows Application(Normally used DataBind() method not available)
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

Sort by
0
Nikolay
Telerik team
answered on 17 Oct 2012, 12:37 PM
Hi Swapnil,

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
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Swapnil
Top achievements
Rank 1
answered on 17 Oct 2012, 01:17 PM
Hi Nikolay,but that code only fetches data from database(which i can show in dataset during debugging) but i want to display it on grid so how can i bind that dataset to RadGrid
Thanks.
0
Accepted
Nikolay
Telerik team
answered on 17 Oct 2012, 02:52 PM
Hello Swapnil,

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
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Ralph
Top achievements
Rank 1
answered on 29 May 2013, 01:57 PM
Sooooo if that isn't working what is the most likely cause?

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];



0
Nikolay
Telerik team
answered on 04 Jun 2013, 04:20 PM
Hello Ralph,

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
RadChart for WinForms is obsolete. Now what?
Tags
GridView
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Swapnil
Top achievements
Rank 1
Ralph
Top achievements
Rank 1
Share this question
or