关于asp 中sql的 select语句

string sq2 = string.Format("select 密码 from' {0}'where 账号='{1}' ", ddl1.Text,txtId.Text);
SqlCommand cmd1 = new SqlCommand(sq2, conn);
string nn = (string)cmd1.ExecuteScalar();
如上所示,select语句报错,我感觉是where附近的问题,但是不知道怎么改,求解

第1个回答  2015-07-15
string sq2 = string.Format("select 密码 from {0}where 账号={1} ", ddl1.Text,txtId.Text)。

把引号去了试试。追问

还是不行,前面{0}部分没有问题,可能是where 账号= 和{1}部分 衔接有错误吧

追答

这样:
string sq2 = string.Format("select 密码 from {0}where 账号='{1}' ", ddl1.Text,txtId.Text)。

{1}这个地方的单引号不能去,把它加上。这样应该没问题了。SQL语言的选择语句就是这么写的了。

本回答被提问者和网友采纳
相似回答