Fail to use oledbparameter

  • Thread starter Thread starter Agnes
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top