在ASP.NET中,在使用到数据库时

来源:百度知道 编辑:UC知道 时间:2024/07/01 02:37:33
在ASP.NET中,在使用到数据库时,
string Key = TextBox2.Text.ToString();
string Key="%"+Key+"%";
string insertSQL = "SELECT FileRoad FROM File1 WHERE Description LIKE"+Key出错;
该怎样改才能从数据库中读出Description跟TextBox2文本值有关的行

字段说明保存在系统表:sysproperties中.

可以用下面的语句查询到.:

"select FileRoad =a.FileRoad ,Description =b.value from syscolumns a left join sysproperties b on a.id=b.id and a.colid=b.smallid
where object_id('File1')=id and
b.value like "+Key

我建议你还是另外加个字段保存描述 不然确实挺麻烦

改为:

string insertSQL = "SELECT FileRoad FROM File1 WHERE Description LIKE '"+Key+"'";

LIKE 要用单引号

单引号和空格加上就ok了。像这种查询最好加上异常处理。

string insertSQL = "SELECT FileRoad FROM File1 WHERE Description LIKE"+Key出错;

帅哥,你LIKE"+Key 中间没有空格。

拼接起来就是 LIKEKey 怎么可能正常使用呢。

应该是 LIKE "+key 这样应该就没问题了。