开发者

sql query in the SqlDataAdapter()

开发者 https://www.devze.com 2022-12-27 08:59 出处:网络
Im using c# .net windows form application. I have loaded names of all the tables pres开发者_如何学编程ent in a database into a combobox.

Im using c# .net windows form application. I have loaded names of all the tables pres开发者_如何学编程ent 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?


I think this should look like:

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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消