Select sql table at run time

6 posts, 0 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 20 Oct 2014 Link to this post

    Sorry for asking such simple think but for some reasons I am not coming right.
    I have a dropdownList that gets populated with the table names: 

    public  void FillDropDownList(string connString)
            {
                String Query = "SELECT * FROM information_schema.tables where Table_Name like 'Table%'";
                using (var cn = new SqlConnection(connString))
                {
                    cn.Open();
                    DataTable dt = new DataTable();
                    try
                    {
                        SqlCommand cmd = new SqlCommand(Query, cn);
                        SqlDataReader myReader = cmd.ExecuteReader();
                        dt.Load(myReader);
                    }
                    catch (SqlException e)
                    {
                       //TODO
                    }
                    radDropDownList1.DataSource = dt;
                    radDropDownList1.ValueMember = "TABLE_NAME";
                    radDropDownList1.DisplayMember = "TABLE_NAME";
                }
            }

    On selectedIndexChanged of the DropDownList I need to fill in the GridView preserving all functionalities (add, update, delete). Basically the table gets choose at runtime. I am not coming right with this and I would appreciate if can point me to a solution or give me a snippet for this.

    Thanks
  2. Dimitar
    Admin
    Dimitar avatar
    2654 posts

    Posted 23 Oct 2014 Link to this post

    Hello Felice,

    Thank you for writing.

    Following the provided information I have created a small sample for you. Generally all you need to do is to change the data source of the grid when the user selects a different table. 

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 23 Oct 2014 in reply to Dimitar Link to this post

    Dear Dimitar,
    thanks for your example. This does not support any edit/delete!
    If you have any with crud I would appreciate.

    However thank you.

  4. Dimitar
    Admin
    Dimitar avatar
    2654 posts

    Posted 24 Oct 2014 Link to this post

    Hello Felice,

    Thank you for writing back.

    RadGridView supports CRUD operations out of the box. In addition the underlying data table will be automatically updated. More information is available here: Updating the Database with ADO.Net.

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 24 Oct 2014 in reply to Dimitar Link to this post

    Dimitars,
    thanks for your answer but because I need to switch tables selected from the dropdown list at run time, and I do not know which tables are in the db rather then they are all structured in the same way, I would not come right using dataAdapters and bindingSources. I have opened another post where I specifically ask for manual CRUD example.
    However thank you.
  6. Dimitar
    Admin
    Dimitar avatar
    2654 posts

    Posted 28 Oct 2014 Link to this post

    Hello Felice,

    Thank you for writing back.

    I noticed the other thread that you have opened. We can continue to discuss this matter there: Manual CRUD - GridView - UI for WinForms Forum.

    If you have any questions, please do not hesitate to contact us.
     
    Regards,
    Dimitar
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top