0

Im using c# .net windows form application. I have loaded names of all the tables present in a database into a combobox.

Now i need to display the contents of the selected table name.

Normally we use

SqlDataAdapter adp= new SqlDataAdapter("Select * from employee", con);

This works fine. but instead of explicitly giving table name i.e employee i need to set it to combobox1.selected item.

I have given like this its not working: string filename= combobox1.selecteditem; SqlDataAdapter adp= new SqlDataAdapter("Select * from filename", con);

How can I select filename dynamically?

2 Answers 2

1

I think this should look like:

string filename= combobox1.selecteditem.ToString();
SqlDataAdapter adp= new SqlDataAdapter("Select * from "+filename, con);
Sign up to request clarification or add additional context in comments.

Comments

0

Just use string concatenation, if you're not afraid of SQL injection:

SqlDataAdapter adp = new SqlDataAdapter("Select * from " +  combobox1.selecteditem, con);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.