看了好久,不知道哪出了问题,我想向textbox中输入关键字进行五个表的模糊查询,查询结果绑定到dataGridview中,不知道为什么,绑定后是空表,但是数据库中有数据。我猜测是读取不到textbox中的内容。代码如下,感谢解答:
private void btnSearch_Click(object sender, EventArgs e)
{
string sql = "select GoodID,GoodName,GoodNo,GoodCode,GPrice,IsPromotion,ProPrice, GoodClassName ,SupplyName ,UserName ,DepartName from Goodtable , GoodClassTable ,SupplyTable ,DepartTable ,UserTable where Goodtable.GoodClassID =GoodClassTable .GoodClassID and Goodtable.UserID =UserTable .UserID and Goodtable.SupplyID =SupplyTable .SupplyID and UserTable .DepartID =DepartTable .DepartID and GoodTable.GoodName like '"+txtGName .Text .ToString ()+"% 'and GoodClassTable.GoodClassName like'" +txtCname .Text .ToString ()+ "'and SupplyTable.SupplyName like'" +txtSSName .Text .ToString ()+"%'";
DataSet ds = DBHelper .GetDS (sql);
dataGridView1.DataSource = ds.Tables[0];
}
------解决方案--------------------------------------------------------
没有 不需要 DataBind 的数据源
------解决方案--------------------------------------------------------
是的,不需要的。而且也没有databind。我觉得还是你sql语句的问题,你拿到数据库执行不会是直接把TextBox的换成数据吧,你应该调试时候把sql的内容拿到数据库执行,我大概看了一下你的sql语句。
有些like后面没有空格