概念是什么(@)选择此代码之前? protected void btnSearch_Click(object sender,EventArgs e) {
SqlDataSource2.SelectCommand = **@**"SELECT tblstore.storname,tblproduct.pid, tblproduct.pname, tblproduct.pprice, tblproduct.publisher, tblproduct.writer FROM tblproduct INNER JOIN tblstore ON tblproduct.storeid = tblstore.storeid WHERE tblproduct.pname LIKE @ likeText;";
SqlDataSource2.SelectParameters.Add("likeText", txtName.Text);
GridView1.EmptyDataText = "not result";
}
答案 0 :(得分:1)
从命令文本
中删除@
和likeText
之间的空格
SqlDataSource2.SelectCommand = @"SELECT tblstore.storname,tblproduct.pid, tblproduct.pname, tblproduct.pprice, tblproduct.publisher, tblproduct.writer FROM tblproduct INNER JOIN tblstore ON tblproduct.storeid = tblstore.storeid WHERE tblproduct.pname LIKE @likeText";
并添加像这样的参数值
SqlDataSource2.SelectParameters.Add("@likeText","%" + txtName.Text + "%");