Connecting Tech Pros Worldwide Forums | Help | Site Map

What is wrong in this code line?

Shapper
Guest
 
Posts: n/a
#1: Nov 19 '05
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


Karl Seguin
Guest
 
Posts: n/a
#2: Nov 19 '05

re: What is wrong in this code line?


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

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)


"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eGjUGDWhFHA.2444@tk2msftngp13.phx.gbl...[color=blue]
> 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
>[/color]


David Browne
Guest
 
Posts: n/a
#3: Nov 19 '05

re: What is wrong in this code line?



"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eGjUGDWhFHA.2444@tk2msftngp13.phx.gbl...[color=blue]
> 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.
>[/color]

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


Eliyahu Goldin
Guest
 
Posts: n/a
#4: Nov 19 '05

re: What is wrong in this code line?


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

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eGjUGDWhFHA.2444@tk2msftngp13.phx.gbl...[color=blue]
> 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
>[/color]


Shapper
Guest
 
Posts: n/a
#5: Nov 19 '05

re: What is wrong in this code line?


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 news:karl REMOVE @ REMOVE openmymind REMOVEMETOO .
ANDME net:
[color=blue]
> 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
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
>
> "Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
> news:eGjUGDWhFHA.2444@tk2msftngp13.phx.gbl...
>[color=green]
> > 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
> >[/color][/color]

Closed Thread