根据姓名从数据库查找学生信息

DAL部分返回列表方法代码
public DataTable GetPeopleList(string strWhere)
{
StringBuilder strSQL = new StringBuilder();
strSQL.Append("SELECT name,gender,status,birthday,school,major,good from[tb_People]");
if (strWhere.Trim() != "")
{
strSQL.Append(" and " + strWhere);
}
return SQLDbHelper.ExecuteDataTable(strSQL.ToString());
}
查询按钮代码
private void button1_Click(object sender, EventArgs e)
{
string con = this.comboBox1.Text.ToString().Trim();
string value = this.textBox1.Text.Trim();
string strWhere = " ";
if (con.Equals("姓名"))
strWhere = "name like '%" + value + "%'";
if (con.Equals("学校"))
strWhere = "school like '%" + value + "%'";
if (con.Equals("专业"))
strWhere = "major like '%" + value + "%'";
this.dataGridView1.DataSource = bllpeople.GetPeopleList(strWhere);
}
报错 and附近有语法错误

img

你把这句sql打印出来,或者打断点看看长什么样,有没有错误,然后把这句sql直接放数据库工具执行以下看能不能执行,排错。