G
Guest
Hello,
I am trying to send Where clause as a parameter. Here is the detail:
Select statment:
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT * " +
" FROM myTable " +
" WHERE @WClause ";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@WClause",
System.Data.SqlDbType.NVarChar, 255, "WClause"));
In the code, I do:
string wClause = "(MyStr LIKE 'zyx%')";
sqlDataAdapter1.SelectCommand.Parameters["@WClause"].Value = wClause;
sqlDataAdapter1.Fill(dataSet11);
I got this error: Line 1: Incorrect syntax near '@WClause'.
I tried this in the query analyzer, it works fine:
select *
from myTable
where (MyStr LIKE 'zyx%')
What is problem?
I am trying to send Where clause as a parameter. Here is the detail:
Select statment:
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT * " +
" FROM myTable " +
" WHERE @WClause ";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@WClause",
System.Data.SqlDbType.NVarChar, 255, "WClause"));
In the code, I do:
string wClause = "(MyStr LIKE 'zyx%')";
sqlDataAdapter1.SelectCommand.Parameters["@WClause"].Value = wClause;
sqlDataAdapter1.Fill(dataSet11);
I got this error: Line 1: Incorrect syntax near '@WClause'.
I tried this in the query analyzer, it works fine:
select *
from myTable
where (MyStr LIKE 'zyx%')
What is problem?