Databinding with DataSet

2 posts, 0 answers
  1. Saikat
    Saikat avatar
    1 posts
    Member since:
    Oct 2011

    Posted 10 Oct 2011 Link to this post

    I am using the Radcontrol Windows Grid to bind data returned by a 'Select' query.
    The piece of code is something like this:

                SqlDataReader dr = null;
                SqlConnection conn = null;
                try
                {
                    this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = true;
                    this.radGridView1.GridElement.BeginUpdate();
                    DataSet ds = new System.Data.DataSet();
                    string connectionString = ConfigurationManager.AppSettings["Conn"];
                    conn = new SqlConnection(connectionString);
                    SqlCommand cmd = new SqlCommand("SELECT * FROM Payment");
                    cmd.Connection = conn;
                    conn.Open();
                   SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = cmd;
                    da.Fill(ds);
                    radGridView1.DataSource = ds.Tables[0].DefaultView;
                 }
                catch (Exception ex)
                {
                }
                finally
                {
                    conn.Close();
                    dr.Dispose();
                }
    Although the dataset is returning rows as a resultset, but when the grid loads, it displayes nothing. Is there anything I am missing.
    I want to Auto generate the columns.
    Thanks,
    Saikat

  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 10 Oct 2011 Link to this post

    Hello,

    This line here:
    this.radGridView1.GridElement.BeginUpdate();
    has no corresponding EndUpdate,

    Please use the newer mechanism provided by telerik the using (radGridView1.DeferRefresh() { ... } ). to avoid this kind of issues in the future.

    I believe it will work like this.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top