Parameters with OleDb

  • Thread starter Thread starter Sheila Jones
  • Start date Start date
S

Sheila Jones

Hello,

A quick question! I have an OleDbCommand object that executes the following
parameter query:
SELECT *, Abs(X-?) AS DeltaX FROM VALUES ORDER BY Abs(X-?)

Although there are two parameters, they both represent the same value. Do I
need to add two parameters to the Parameters collection, or is there a way
to indicate that the same parameter should be used in both places? Thanks.
 
Hi Sheila,

I am not 100% sure on this but I think you'll need two parameters.
 
Thanks for the quick reply. I couldn't see a way of doing it either, but
does anybody know for sure?


Miha Markic said:
Hi Sheila,

I am not 100% sure on this but I think you'll need two parameters.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Sheila Jones said:
Hello,

A quick question! I have an OleDbCommand object that executes the following
parameter query:
SELECT *, Abs(X-?) AS DeltaX FROM VALUES ORDER BY Abs(X-?)

Although there are two parameters, they both represent the same value.
Do
I
need to add two parameters to the Parameters collection, or is there a way
to indicate that the same parameter should be used in both places? Thanks.
 
Sheila:

From the query it looks like the COlumn name is the parameter and I don't
believe it's going to work..
Since you know they are the same, you could simply create a local variable
and set the local variable to whatever the var that you pass in is.
However, if I understand the query correctly, if you want to Variable to be
used as a column name, I don't think it's going to fly.

Sheila Jones said:
Thanks for the quick reply. I couldn't see a way of doing it either, but
does anybody know for sure?


Miha Markic said:
Hi Sheila,

I am not 100% sure on this but I think you'll need two parameters.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Sheila Jones said:
Hello,

A quick question! I have an OleDbCommand object that executes the following
parameter query:
SELECT *, Abs(X-?) AS DeltaX FROM VALUES ORDER BY Abs(X-?)

Although there are two parameters, they both represent the same value.
Do
I
need to add two parameters to the Parameters collection, or is there a way
to indicate that the same parameter should be used in both places? Thanks.
 
No, the parameter is not a column name, it's an integer value. The purpose
of the query is to produce a list sorted such that values of X closest to
the specified parameter value come first, e.g. if the parameter value is
100, the values of X might go 99, 102, 90, 85, 120 etc.


William Ryan eMVP said:
Sheila:

From the query it looks like the COlumn name is the parameter and I don't
believe it's going to work..
Since you know they are the same, you could simply create a local variable
and set the local variable to whatever the var that you pass in is.
However, if I understand the query correctly, if you want to Variable to be
used as a column name, I don't think it's going to fly.

Sheila Jones said:
Thanks for the quick reply. I couldn't see a way of doing it either, but
does anybody know for sure?


Miha Markic said:
Hi Sheila,

I am not 100% sure on this but I think you'll need two parameters.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hello,

A quick question! I have an OleDbCommand object that executes the
following
parameter query:
SELECT *, Abs(X-?) AS DeltaX FROM VALUES ORDER BY Abs(X-?)

Although there are two parameters, they both represent the same
value.
Do
I
need to add two parameters to the Parameters collection, or is there
a
way
to indicate that the same parameter should be used in both places? Thanks.
 
Back
Top