How to bind dataset to Radgrid in Windows App.

6 posts, 1 answers
  1. Swapnil
    Swapnil avatar
    30 posts
    Member since:
    Sep 2012

    Posted 17 Oct 2012 Link to this post

    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.
  2. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 17 Oct 2012 Link to this post

    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.
  3. Swapnil
    Swapnil avatar
    30 posts
    Member since:
    Sep 2012

    Posted 17 Oct 2012 Link to this post

    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.
  4. Answer
    Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 17 Oct 2012 Link to this post

    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.
  5. Ralph
    Ralph avatar
    17 posts
    Member since:
    May 2011

    Posted 29 May 2013 Link to this post

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



  6. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 04 Jun 2013 Link to this post

    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?
Back to Top