Vb ado

matty1990

New Member
I'm having trouble reguarding Visual Basic Express 2010...

I'm using LocalDB and trying to connect to it using VB Express 2010, I've added ADO 2.8 as a reference, which allows me to use the connection method, however when I want check the state....

if(cObject.State = adStateOpen)
...


an error is produced stating that adStateOpen is not declared.
Help!
 
I've not used VB in quite a long time, but, make sure that you are spelling adStateOpen correctly and that it is actually declared somewhere (Some more of your code would be useful). Also, when using an if statement, it should be:

Code:
if (cObject.State == adStateOpen)

note the ==
 
Adding the reference (in the solution explorer) is not the only thing you need to do in order to use it.You must also add it in the NAMESPACE section (usually at the top of the code) and then initialize it and give it your name.In this case your name I suppose would be "adStateOpen".So declare that object which you added as a reference using that name "adStateOpen".Once that has been done,you can use it.

For example you cannot use a string called "LOL" if you do not declare it somewhere first.Following example won't work:

MessageBox.Show(LOL.ToString());

Following example will work:

string LOL="Yay!"
MessageBox.Show(LOL.ToString());

Here is an image example of declared reference:
DeclareLocalReferencePreview.png


Or:
DeclareFieldPreview.png


Also when using the IF keyword you must always include double equals "==" in the IF statement and not just one equal "=".However in statements that are not IF,ELSE IF and so on statements...,usually in most cases only one equal "=" is the correct way of doing things.Such as:

checkBoxControl.Checked=true;




Cheers!
 
Last edited:
Back
Top