473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SQL parameter: what is wrong here?

Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P

Sep 6 '06 #1
11 4315
Pamela,

When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.

If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.

Kerry Moorman
"pa***********@libero.it" wrote:
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P

Sep 6 '06 #2

Kerry Moorman wrote:
Pamela,

When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.

If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.
I really don't know the differences between OleDb and ODBC or SQL, but
I would have suggested adding a:

declare @Pinco as varchar(<maxsize>)
before the Select.

>
"pa***********@libero.it" wrote:
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P
Sep 6 '06 #3
pa***********@libero.it wrote:
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
It might want the maximum length of the string as defined when you created
the table, e.g.:
Dim OleDbParameter As OleDbParameter OleDbCommand.Parameters.Add("@Pinco",
OleDbType.VarWChar, 24)

Andrew
Sep 6 '06 #4
Ok Kerry thanks , I tried

where C.City = ?

with this code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()

this returns no record, although records with C.City = "Berlin" are
there.

What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?

-P


Kerry Moorman ha scritto:
Pamela,

When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.

If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.

Kerry Moorman
"pa***********@libero.it" wrote:
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P
Sep 6 '06 #5
Thanks Z and Andrew for your suggestions too.
It seems I have some problems to make this work.
I want to avoid the variable definition because I would like
to write some code to work with several DB. The OleDB connection
could be with SQLserver, Oracle, Access, as400 and other dbms.
This is my most important point I need some *general* code.

Do you think that in my case would be more advisable that I do
a manual substitution of the parameter with the value in the query?

I mean I could examine the query and, when I find @Param1, @OtherParam,
@Etc
I could substitute those with an ordered list of values supplied by the
user
through some interface. Would that be advisable and, most importantly
would it work on all platforms?

What is the best way to do the string replacement. I am afraid that if
one
has for instance: @Pinco and @PincoPallo the substitution of the first
parameter could prevent the substitution of the second ...

@Pinco = "Berlin" would cause the destruction of the second identifier
: BerlinPallo

-p

Andrew Morton ha scritto:
pa***********@libero.it wrote:
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)

It might want the maximum length of the string as defined when you created
the table, e.g.:
Dim OleDbParameter As OleDbParameter OleDbCommand.Parameters.Add("@Pinco",
OleDbType.VarWChar, 24)

Andrew
Sep 6 '06 #6
Pamela,

I am not at a machine with SQL Server, so I can't try this code. But you
might try replacing:

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

with

OleDbCommand.Parameters.Add ("City", "Berlin")

In this example, "City" is just a placeholder name for the parameter and
does not need to match the actual column name in the table.

Kerry Moorman
"pa***********@libero.it" wrote:
Ok Kerry thanks , I tried

where C.City = ?

with this code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()

this returns no record, although records with C.City = "Berlin" are
there.

What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?

-P


Kerry Moorman ha scritto:
Pamela,

When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.

If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.

Kerry Moorman
"pa***********@libero.it" wrote:
Hi I am executing some simple sample code:
>
Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)
>
Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"
>
Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...
>
I use this query:
>
SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where
>
C.City = @Pinco
>
It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).
>
What's the problem here? How do I fix it to work with a general OleDB
connection?
>
-P
>
>

Sep 6 '06 #7
hi Kerry

it says.

System.InvalidOperationException occurred
Message="OleDbCommand.Prepare method requires all parameters to have
an explicitly set type."

Do you think that a "direct substitution" would be better and more
robust?

-p

Kerry Moorman ha scritto:
Pamela,

I am not at a machine with SQL Server, so I can't try this code. But you
might try replacing:

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

with

OleDbCommand.Parameters.Add ("City", "Berlin")

In this example, "City" is just a placeholder name for the parameter and
does not need to match the actual column name in the table.

Kerry Moorman
"pa***********@libero.it" wrote:
Ok Kerry thanks , I tried

where C.City = ?

with this code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()

this returns no record, although records with C.City = "Berlin" are
there.

What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?

-P


Kerry Moorman ha scritto:
Pamela,
>
When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.
>
If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.
>
Kerry Moorman
>
>
"pa***********@libero.it" wrote:
>
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P
Sep 6 '06 #8
Pamela,

If by direct substitution you mean placing your data values directly into
the SQL Select statement instead of using parameters, then definitely not.

Parameters help prevent SQL injection attacks and are absolutely needed for
security.

I'll see if I can get an example of working code when I am able to be on a
machine with SQL Server.

But perhaps you have some additional code that you have not shown that might
be causing the problem?

Kerry Moorman
"pa***********@libero.it" wrote:
hi Kerry

it says.

System.InvalidOperationException occurred
Message="OleDbCommand.Prepare method requires all parameters to have
an explicitly set type."

Do you think that a "direct substitution" would be better and more
robust?

-p

Kerry Moorman ha scritto:
Pamela,

I am not at a machine with SQL Server, so I can't try this code. But you
might try replacing:

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

with

OleDbCommand.Parameters.Add ("City", "Berlin")

In this example, "City" is just a placeholder name for the parameter and
does not need to match the actual column name in the table.

Kerry Moorman
"pa***********@libero.it" wrote:
Ok Kerry thanks , I tried
>
where C.City = ?
>
with this code:
>
Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)
>
Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)
>
Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
>
this returns no record, although records with C.City = "Berlin" are
there.
>
What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?
>
-P
>
>
>
>
>
>
Kerry Moorman ha scritto:
>
Pamela,

When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.

If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.

Kerry Moorman


"pa***********@libero.it" wrote:

Hi I am executing some simple sample code:
>
Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)
>
Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"
>
Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...
>
I use this query:
>
SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where
>
C.City = @Pinco
>
It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).
>
What's the problem here? How do I fix it to work with a general OleDB
connection?
>
-P
>
>
>
>

Sep 6 '06 #9
Kerry Moorman ha scritto:
Pamela,

If by direct substitution you mean placing your data values directly into
the SQL Select statement instead of using parameters, then definitely not.

Parameters help prevent SQL injection attacks and are absolutely needed for
security.
Ok Thanks. good advice.
>
I'll see if I can get an example of working code when I am able to be on a
machine with SQL Server.
Thank you, that would be really nice of you.
>
But perhaps you have some additional code that you have not shown that might
be causing the problem?
No. Everything works fine. The only problem is with parameters. What I
need is a simple way to let the user define 1 or more parameters in a
query passed via OleDB. And that should be not platform-specific, but
should work whatever is the dbms to which I am connected and whatever
is the field. I assume to know nothing about the data type to which the
parameter will refer to.

Thanks indeed Kerry.

-P
>
Kerry Moorman
"pa***********@libero.it" wrote:
hi Kerry

it says.

System.InvalidOperationException occurred
Message="OleDbCommand.Prepare method requires all parameters to have
an explicitly set type."

Do you think that a "direct substitution" would be better and more
robust?

-p

Kerry Moorman ha scritto:
Pamela,
>
I am not at a machine with SQL Server, so I can't try this code. But you
might try replacing:
>
Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)
>
with
>
OleDbCommand.Parameters.Add ("City", "Berlin")
>
In this example, "City" is just a placeholder name for the parameter and
does not need to match the actual column name in the table.
>
Kerry Moorman
>
>
"pa***********@libero.it" wrote:
>
Ok Kerry thanks , I tried

where C.City = ?

with this code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()

this returns no record, although records with C.City = "Berlin" are
there.

What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?

-P






Kerry Moorman ha scritto:

Pamela,
>
When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.
>
If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.
>
Kerry Moorman
>
>
"pa***********@libero.it" wrote:
>
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P


Sep 6 '06 #10
Pamela,

Here is an example that selects movie directors based on nationality, using
a parameter:

Dim cn As New OleDbConnection("Provider=SQLOLEDB;Data
Source=(local)\SQLExpress;Initial Catalog=MoviesToGoSQL;User
ID=sa;Password=xxxx")
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Dim NationalityValue As String = "American"

cmd.CommandText = "Select * From Directors Where Nationality = ?"
cmd.Parameters.Add("NationalityParameter", NationalityValue)

cn.Open()
cmd.Connection = cn

dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

If dr.HasRows Then
MsgBox("Got data")
Else
MsgBox("No data")
End If

dr.Close()

Kerry Moorman
"pa***********@libero.it" wrote:
Kerry Moorman ha scritto:
Pamela,

If by direct substitution you mean placing your data values directly into
the SQL Select statement instead of using parameters, then definitely not.

Parameters help prevent SQL injection attacks and are absolutely needed for
security.

Ok Thanks. good advice.

I'll see if I can get an example of working code when I am able to be on a
machine with SQL Server.

Thank you, that would be really nice of you.

But perhaps you have some additional code that you have not shown that might
be causing the problem?

No. Everything works fine. The only problem is with parameters. What I
need is a simple way to let the user define 1 or more parameters in a
query passed via OleDB. And that should be not platform-specific, but
should work whatever is the dbms to which I am connected and whatever
is the field. I assume to know nothing about the data type to which the
parameter will refer to.

Thanks indeed Kerry.

-P

Kerry Moorman
"pa***********@libero.it" wrote:
hi Kerry
>
it says.
>
System.InvalidOperationException occurred
Message="OleDbCommand.Prepare method requires all parameters to have
an explicitly set type."
>
Do you think that a "direct substitution" would be better and more
robust?
>
-p
>
Kerry Moorman ha scritto:
>
Pamela,

I am not at a machine with SQL Server, so I can't try this code. But you
might try replacing:

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

with

OleDbCommand.Parameters.Add ("City", "Berlin")

In this example, "City" is just a placeholder name for the parameter and
does not need to match the actual column name in the table.

Kerry Moorman


"pa***********@libero.it" wrote:

Ok Kerry thanks , I tried
>
where C.City = ?
>
with this code:
>
Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)
>
Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)
>
Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
>
this returns no record, although records with C.City = "Berlin" are
there.
>
What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?
>
-P
>
>
>
>
>
>
Kerry Moorman ha scritto:
>
Pamela,

When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.

If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.

Kerry Moorman


"pa***********@libero.it" wrote:

Hi I am executing some simple sample code:
>
Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)
>
Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"
>
Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...
>
I use this query:
>
SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where
>
C.City = @Pinco
>
It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).
>
What's the problem here? How do I fix it to work with a general OleDB
connection?
>
-P
>
>
>
>
>
>

Sep 7 '06 #11
Thanks Kerry. Very sweet. I am gonna try it immediately.

-Is this supposed to work for any database ?
-Can I use multiple parameters? Just add them?
-P
Kerry Moorman ha scritto:
Pamela,

Here is an example that selects movie directors based on nationality, using
a parameter:

Dim cn As New OleDbConnection("Provider=SQLOLEDB;Data
Source=(local)\SQLExpress;Initial Catalog=MoviesToGoSQL;User
ID=sa;Password=xxxx")
Dim cmd As New OleDbCommand
Dim dr As OleDbDataReader
Dim NationalityValue As String = "American"

cmd.CommandText = "Select * From Directors Where Nationality = ?"
cmd.Parameters.Add("NationalityParameter", NationalityValue)

cn.Open()
cmd.Connection = cn

dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

If dr.HasRows Then
MsgBox("Got data")
Else
MsgBox("No data")
End If

dr.Close()

Kerry Moorman
"pa***********@libero.it" wrote:
Kerry Moorman ha scritto:
Pamela,
>
If by direct substitution you mean placing your data values directly into
the SQL Select statement instead of using parameters, then definitely not.
>
Parameters help prevent SQL injection attacks and are absolutely needed for
security.
Ok Thanks. good advice.
>
I'll see if I can get an example of working code when I am able to be on a
machine with SQL Server.
Thank you, that would be really nice of you.
>
But perhaps you have some additional code that you have not shown that might
be causing the problem?
No. Everything works fine. The only problem is with parameters. What I
need is a simple way to let the user define 1 or more parameters in a
query passed via OleDB. And that should be not platform-specific, but
should work whatever is the dbms to which I am connected and whatever
is the field. I assume to know nothing about the data type to which the
parameter will refer to.

Thanks indeed Kerry.

-P
>
Kerry Moorman
>
>
"pa***********@libero.it" wrote:
>
hi Kerry

it says.

System.InvalidOperationException occurred
Message="OleDbCommand.Prepare method requires all parameters to have
an explicitly set type."

Do you think that a "direct substitution" would be better and more
robust?

-p

Kerry Moorman ha scritto:

Pamela,
>
I am not at a machine with SQL Server, so I can't try this code. But you
might try replacing:
>
Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)
>
with
>
OleDbCommand.Parameters.Add ("City", "Berlin")
>
In this example, "City" is just a placeholder name for the parameter and
does not need to match the actual column name in the table.
>
Kerry Moorman
>
>
"pa***********@libero.it" wrote:
>
Ok Kerry thanks , I tried

where C.City = ?

with this code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim p As New OleDbParameter
p.Value = "Berlin"
OleDbCommand.Parameters.Add(p)

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()

this returns no record, although records with C.City = "Berlin" are
there.

What I am still missing. I'd like a method which works generally with
OleDB (irrelevant of the database, if possible) ?

-P






Kerry Moorman ha scritto:

Pamela,
>
When using the OleDb namespace with SQL Server, I don't think you can use
named parameters. To use named parameters you would need to use the SQLClient
namespace.
>
If you change your Select statement by replacing @Pinco with the
question-mark placeholder, ?, I think your code should work.
>
Kerry Moorman
>
>
"pa***********@libero.it" wrote:
>
Hi I am executing some simple sample code:

Using OleDbCommand As New OleDbCommand(Me.DBQuery.Text,
Me.OleDbConnection)

Dim OleDbParameter As OleDbParameter =
OleDbCommand.Parameters.Add("@Pinco", OleDbType.VarWChar)
OleDbParameter.Direction = ParameterDirection.Input
OleDbParameter.Value = "Berlin"

Using OleDbDataReader As OleDbDataReader =
OleDbCommand.ExecuteReader()
'...

I use this query:

SELECT
C.Country AS "Country",
C.City AS "City"
FROM
Customers C
where

C.City = @Pinco

It works with ACCESS, but gives error with SQL Server (says variable
has not been defined).

What's the problem here? How do I fix it to work with a general OleDB
connection?

-P




Sep 7 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dan | last post by:
I've run into an interesting problem, and seemed to have stumped 3 newsgroups and 2 other forums. For some reason when I try to insert a record into a SQL table that has a Text column, the...
5
by: Matt | last post by:
I have a simple JS function that I want to return a true or false value based on the parameter passed in. At this point of time I receive the error "'True' is undefined". Here is my code below. ...
2
by: J Krugman | last post by:
I have a form with a couple of submit buttons, plus a "pseudolink" that is also supposed to submit the form; the submitted form data feeds to a CGI script. The two submit buttons have the name...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
20
by: Brien King | last post by:
If I have a parameter that has an Object type (as opposed to something like a string), can I make that parameter a CONST? Right now, if you pass an object into a sub/function, that sub/function...
4
by: Ranginald | last post by:
Hi, I'm having trouble passing a parameter from my default.aspx page to my default2.aspx page. I have values from a query in a list box and the goal is to pass the "catID" from default.aspx...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
6
by: humblemark | last post by:
Hello, I try to give a parameter in the function tt; but omething went wrong?? Any idea what i can do?? int ret_integer() { return 76;
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.