Fail to use oledbparameter

A

Agnes

Dim ocmdElem As New OleDbCommand()
With ocmdElem
.Parameters.Add(New OleDbParameter("@cocode",
OleDbType.VarChar, 10, "TEST"))
.CommandText = "select loginid from coinfo where code
=@cocode "
.Connection = New OleDbConnection("Provider =
VfpOleDB.1;Data Source = d:\cgl\vfpmaster\ttsdata\tts.dbc")
.Connection.Open()
.ExecuteNonQuery() <-- Error It said"Missing Operand"
End With

Please help
 
P

Phil Hall

Agnes said:
Dim ocmdElem As New OleDbCommand()
With ocmdElem
.Parameters.Add(New OleDbParameter("@cocode",
OleDbType.VarChar, 10, "TEST"))
.CommandText = "select loginid from coinfo where code
=@cocode "
.Connection = New OleDbConnection("Provider =
VfpOleDB.1;Data Source = d:\cgl\vfpmaster\ttsdata\tts.dbc")
.Connection.Open()
.ExecuteNonQuery() <-- Error It said"Missing Operand"
End With

Please help

Dear Agnes

There are two things wrong with the above code that I can see:

(1) You are executing a SELECT query which is meant to return data, but
you don't appear to be assigning the result to anything

(2) A SELECT command is normally accompanied by a Datareader to
retrieve the results using the ExecuteReader method. The
ExecuteNonQuery method is for UPDATE, INSERT and DELETE commands etc.

Or am I missing something?

Phil Hall
 
P

Phil Hall

Hi again Agnes

I've just noticed something else. Try putting a space between the = and
the @ character in the CommandText, i.e.

You have it as

..CommandText = "select loginid from coinfo where code =@cocode"

replace it with:

..CommandText = "select loginid from coinfo where code = @cocode"

That may be what is causing the error message.

Phil Hall
 
A

Agnes

If I change the command text into "select loginid from coinfo where code
='Test' "
there is no error , So I wonder whether my parameter passing is wrong
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top