我们如何在c#中使用存储在字符串变量中的表名

时间:2015-11-28 09:55:38

标签: c#-4.0

string tablename = DropDownList1.SelectedValue.ToString()
string id = TextBox1.Text;
adp = new SqlDataAdapter("select * from '" + tablename + "' where id='" + id + "'", obj.connect());
DataSet ds = new DataSet();
adp.Fill(ds);

1 个答案:

答案 0 :(得分:-1)

string.Format(" select * from {0} where id = {1}",tablename,id)