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

Select sql table at run time

5 Answers 35 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 20 Oct 2014, 06:32 PM
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

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 23 Oct 2014, 10:38 AM
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.

 
0
Felice
Top achievements
Rank 1
answered on 23 Oct 2014, 10:59 AM
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.

0
Dimitar
Telerik team
answered on 24 Oct 2014, 03:53 PM
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.

 
0
Felice
Top achievements
Rank 1
answered on 24 Oct 2014, 04:01 PM
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.
0
Dimitar
Telerik team
answered on 28 Oct 2014, 02:59 PM
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.

 
Tags
GridView
Asked by
Felice
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Felice
Top achievements
Rank 1
Share this question
or