vfp oledbcommand [Fail]

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

Dim authConnection As New OleDbConnection("Provider =
VfpOleDB.1;Data Source = d:\cgl\vfpmaster\ttsdata\tts.dbc")
authConnection.Open()
Dim authCommand As String = "select loginid from coinfo
where loginid = @cocode "

oleCommand.Parameters.Add("@cocode", OleDbType.VarChar,
10).Value = "1001"
or oleCommand.Parameters.Add(new oledbparameter("@cocode",
OleDbType.VarChar, 10)).Value = "1001"
Dim drRv As OleDbDataReader =
oleCommand.ExecuteReader <---ERROR

Please help, I don't know what's wrong with my statment.
For the same syntax, I can run very well in my sql server,
However, When I change into oleddb command.
I got "missing operand" error.
 
Agnes,

What is the meaning from this boolean code that you are using?

oleCommand.Parameters.Add("@cocode", OleDbType.VarChar,
10).Value = "1001"
or oleCommand.Parameters.Add(new oledbparameter("@cocode",
OleDbType.VarChar, 10)).Value = "1001"


In my idea does it nothing

Cor
 
Brrrrrrrrr

That or is in your message is no code but a seperator of two possibilities.

An error that mostly is done by OleDB is that there are added to many times
a paramaeter.

If you add it than you add it to an array, that array it is using. Therefore
you should only add them one time and than change the value as often as you
want.

Have a look at this page how to use OleDB parameters.

http://www.vb-tips.com/dbpages.aspx?ID=550279ec-6767-44ff-aaa3-eb8b44af0137

I hope this helps,

Cor
 
Hi Agnes,

"@" preceding a variable name has a different use in FoxPro than it does in
SQL Server. This works for me:

Try

Dim cn1 As New OleDbConnection( _
"Provider=VFPOLEDB.1;Data Source=C:\Temp\;")
cn1.Open()
'-- Make some VFP data to play with
Dim cmd1 As New OleDbCommand( _
"Create Table TestParameter (Field1 C(10))", cn1)
Dim cmd2 As New OleDbCommand( _
"Insert Into TestParameter Values ('Hello')", cn1)
Dim cmd3 As New OleDbCommand( _
"Insert Into TestParameter Values ('World')", cn1)
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
cmd3.ExecuteNonQuery()

Dim cmd4 As New OleDbCommand( _
"Select * From TestParameter Where Field1 = ?", cn1)
Dim p1 As New OleDbParameter("Field1", "World")
Dim da1 As New OleDbDataAdapter(cmd4)
Dim ds1 As New DataSet
Dim dr1 As DataRow

cmd4.Parameters.Add(p1)
da1.Fill(ds1)
For Each dr1 In ds1.Tables(0).Rows
Console.WriteLine(dr1.Item(0).ToString())
Next
Console.ReadLine()
cn1.Close()

Catch e As Exception
MsgBox(e.ToString())
End Try
 
Back
Top