注册 登录
编程论坛 ASP.NET技术论坛

求助模糊查询问题

助人为乐 发布于 2007-10-30 14:49, 669 次点击
这是源码:

SqlConnection conn = db.condb();
SqlDataAdapter sdr = new SqlDataAdapter();
sdr.SelectCommand = new SqlCommand("select * from news where id like '%" +this.TextBox1.Text.Trim()+"%'",conn);
DataSet ds = new DataSet();
sdr.Fill(ds,"view");
DataGrid1.DataSource = ds.Tables["view"];
DataGrid1.DataKeyField = "id";
DataGrid1.DataBind();
我测测的时候 点击搜索按钮 datagrid 里显示是空白的 请问我哪里写的不对?
另外我如果判断没有查询的数据应该怎么写?

[此贴子已经被作者于2007-10-30 14:50:03编辑过]

4 回复
#2
bygg2007-10-30 15:55
没有错,只是不知道你的select * from news where id like '%" +this.TextBox1.Text.Trim()+"%'执行出来有没有数据
#3
垃圾的沉默2007-10-30 17:37
数据库怎么做的?? ID是不是唯一的值
#4
cyyu_ryh2007-10-30 18:02

你在查询分析器里能查询处内容吗?

#5
助人为乐2007-10-31 13:54

真是马虎 我把datagrid里的一个字段写错了 让你们费心了 谢谢大家

1