You can't do that. Parameters are meant to send literal values (strings,
integers, dates, etc). Not executable statements (or pieces of them).
You can make the query: "Select * From MyTable WHERE MyCol like @dotnet.itags.org.val"
Then add a variable called "@dotnet.itags.org.val", and set its value to whatever you need it
to be.
"JIM.H." <JIMH@dotnet.itags.org.discussions.microsoft.com> wrote in message
news:68BA5695-005D-402A-8D6C-0C3044087E1E@dotnet.itags.org.microsoft.com...
> 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 @dotnet.itags.org.WClause ";
> this.sqlSelectCommand1.Connection = this.sqlConnection1;
> this.sqlSelectCommand1.Parameters.Add(new
> System.Data.SqlClient.SqlParameter("@dotnet.itags.org.WClause",
> System.Data.SqlDbType.NVarChar, 255, "WClause"));
>
> In the code, I do:
> string wClause = "(MyStr LIKE 'zyx%')";
> sqlDataAdapter1.SelectCommand.Parameters["@dotnet.itags.org.WClause"].Value = wClause;
> sqlDataAdapter1.Fill(dataSet11);
> I got this error: Line 1: Incorrect syntax near '@dotnet.itags.org.WClause'.
> I tried this in the query analyzer, it works fine:
> select *
> from myTable
> where (MyStr LIKE 'zyx%')
> What is problem?
>The problem is with that: I need to add or remove constraints based on the
user input. For string fields I use %. However, for example "Where (myId =
@.ID) " if user did not give @.ID, that should not have any impact on the quer
y
result. How can I do this?
"Marina" wrote:
> You can't do that. Parameters are meant to send literal values (strings,
> integers, dates, etc). Not executable statements (or pieces of them).
> You can make the query: "Select * From MyTable WHERE MyCol like @.val"
> Then add a variable called "@.val", and set its value to whatever you need
it
> to be.
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:68BA5695-005D-402A-8D6C-0C3044087E1E@.microsoft.com...
>
>
You can adjust your query based on input. Just leave that condition out of
the whereclause.
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:8D955F1E-6FB8-421A-B170-A7FAD1A598BA@.microsoft.com...
> The problem is with that: I need to add or remove constraints based on the
> user input. For string fields I use %. However, for example "Where (myId =
> @.ID) " if user did not give @.ID, that should not have any impact on the
> query
> result. How can I do this?
> "Marina" wrote:
>
Thanks for the reply. I used this format it works Where (myId = @.ID OR @.ID I
S
NULL)
"Marina" wrote:
> You can adjust your query based on input. Just leave that condition out of
> the whereclause.
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:8D955F1E-6FB8-421A-B170-A7FAD1A598BA@.microsoft.com...
>
>
Saturday, March 31, 2012
what is problem here
Labels:
asp,
dates,
executable,
integers,
literal,
meant,
net,
parameters,
pieces,
statements,
strings,
values
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment