概念是什么(@)在选择此代码之前?

时间:2013-11-12 06:34:02

标签: asp.net

概念是什么(@)选择此代码之前?     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";

}

1 个答案:

答案 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 + "%");