How to pass a variable to the SelectCommand of a SqlDataSource?

后端 未结 10 647
耶瑟儿~
耶瑟儿~ 2020-12-01 00:37

I want to pass variable from the code behind to the SelectCommand of a SqlDataSource?

I don\'t want to use built-in parameter types (like ControlParameter, QueryStri

10条回答
  •  遥遥无期
    2020-12-01 00:44

    SqlDataSource1.SelectCommand = "select * from ta where name like '%'+@p+'%'";
    if (SqlDataSource1.SelectParameters.Count == 0)
    {
       SqlDataSource1.SelectParameters.Add("p", DbType.String, TextBox1.Text);
    }
    SqlDataSource1.SelectParameters["p"].DefaultValue = TextBox1.Text;
    

提交回复
热议问题