What is wrong in this code line?

S

Shapper

Hello,

I am adding a parameter, with only one code line, when I set a
connection to an Access database:

With dbCommand.Parameters

.Add(New System.Data.OleDb.OleDbParameter("@title",
OleDbType.VarWChar).Value = "Title Text")

End With

I get the error: "The OleDbParameterCollection only accepts non-null
OleDbParameter type objects, not Boolean objects."

Why is that?
I have been searching for the solution in Google and I can't see why
this is not working.

Thanks,
Miguel
 
K

Karl Seguin

Your vb.net syntax is all messy.

you have .Add( <CODE HERE > )

your <CODE HERE> looks like:

New System.Data.OleDb.OleDbParameter("@title", OleDbType.VarWChar).Value =
"Title Text"

which, I guess, is doing an equallity operartion, instead of an assignment.
That is, it's checking if
New System.Data.OleDb.OleDbParameter("@title", OleDbType.VarWChar).Value
IS EQUAL TO
"Title Text"

and return false...hence why it's saying you can't add false to .Add()

It should look like:

..Add(New System.Data.OleDb.OleDbParameter("@title",
OleDbType.VarWChar)).Value = "Title Text"

Karl
 
D

David Browne

Shapper said:
Hello,

I am adding a parameter, with only one code line, when I set a connection
to an Access database:

With dbCommand.Parameters

.Add(New System.Data.OleDb.OleDbParameter("@title",
OleDbType.VarWChar).Value = "Title Text")

End With

I get the error: "The OleDbParameterCollection only accepts non-null
OleDbParameter type objects, not Boolean objects."

Why is that?
I have been searching for the solution in Google and I can't see why this
is not working.

Because

.Add(New System.Data.OleDb.OleDbParameter("@title",
OleDbType.VarWChar).Value = "Title Text")

is the same as

dim p as New System.Data.OleDb.OleDbParameter("@title", OleDbType.VarWChar)
dim b as Boolean = (p.Value = "TitleText")
..Add(b);

David
 
E

Eliyahu Goldin

New System.Data.OleDb.OleDbParameter("@title", OleDbType.VarWChar).Value =
"Title Text"

is a boolean expression that returns true if New
System.Data.OleDb.OleDbParameter("@title", OleDbType.VarWChar).Value is
equal "Title Text" and false otherwise.

Eliyahu
 
S

Shapper

Hi Karl,

I had tried that before but I get this error message:
error BC30456: 'Value' is not a member of 'Integer'

In Visual Studio the part
With dbCommand.Parameters
.Add(New System.Data.OleDb.OleDbParameter("@title",
OleDbType.VarWChar)).Value
End With

Is underlined and associated with that error.

Any idea?

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message REMOVE @ REMOVE openmymind REMOVEMETOO .
ANDME net:
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top