473,383 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Accessing data from a ADODB.recordset

Hi,

I'm trying to write an app that reads data from a table
into a string variable for later use in my program.
Below is a snippet of the code I'm using, which compiles
ok, but at runtime I get and error 'Object reference not
set to an instance of an object.' as soon as I try to
access the data in the fields, I.e. at the line that
reads 'KeyFlags(i) = rstFields("keyflag").value'

Anyone tell me where I'm going wrong?

strSQL = "SELECT fieldname, keyflag,
mandatoryflag ,vendorKey,tablename from field_relates "
strSQL = strSQL & "where fieldname = '" &
Remove_Quotes(namearray(i)) & "' AND tablename = '" &
CmdArgs(0) & "'"
Dim rstFields
rstFields = CreateObject("ADODB.Recordset")
rstFields.open(strSQL, strConn)
If rstFields.eof Then
MsgBox("**Error:- Field name " & namearray
(i) & " not registered for " & CmdArgs(0) & " load at
position " & i + 1)
FileClose(1)
Return 4
End If
KeyFlags(i) = rstFields("keyflag").value
MandatoryFlags(i) = rstFields
("mandatoryflag").value
VendorKey(i) = rstFields("VendorKey").value
If MandatoryFlags(i) = "Y" Then ManCount += 1
If VendorKey(i) = "Y" Then VenCount += 1
rstFields.close()

Nov 19 '05 #1
6 13981
Thanks CJ.

Been so used to coding ASP an VB didn't realise .net was
that different. Thansks for the namespace pointer I can
go dig around.

Andy
-----Original Message-----

This looks like VB6, in which case this is the wrong board, but I'll throwan answer your way. And if its Not VB6, and this is how your coding .NET...go buy a book. Becuase this is bad. Really bad...

Don't take that offensivly, but your late binding (if binding a datatype atall to everything)

First of all, if you get a Object null error (not set to instance) you haveto use the new constructor. And since you didn't tell us where exactly itwas bombing, I could see about 8 places it would.

for example, dont declare something without a datatype. (Dim rstFileds)
do

Dim rstFields as ADODB.Recordset.

Second of all, if this is .NET code, then don't use ADODB. Use theSystem.data namespace.

If you don't know what that is...

put it back in the box, and buy a book... then you may have it back.
-CJ

"Andy Barber" <an****@blueyonder.co.uk> wrote in message
news:05****************************@phx.gbl...
Hi,

I'm trying to write an app that reads data from a table
into a string variable for later use in my program.
Below is a snippet of the code I'm using, which compiles
ok, but at runtime I get and error 'Object reference not
set to an instance of an object.' as soon as I try to
access the data in the fields, I.e. at the line that
reads 'KeyFlags(i) = rstFields("keyflag").value'

Anyone tell me where I'm going wrong?

strSQL = "SELECT fieldname, keyflag,
mandatoryflag ,vendorKey,tablename from field_relates "
strSQL = strSQL & "where fieldname = '" &
Remove_Quotes(namearray(i)) & "' AND tablename = '" &
CmdArgs(0) & "'"
Dim rstFields
rstFields = CreateObject("ADODB.Recordset")
rstFields.open(strSQL, strConn)
If rstFields.eof Then
MsgBox("**Error:- Field name " & namearray (i) & " not registered for " & CmdArgs(0) & " load at
position " & i + 1)
FileClose(1)
Return 4
End If
KeyFlags(i) = rstFields("keyflag").value
MandatoryFlags(i) = rstFields
("mandatoryflag").value
VendorKey(i) = rstFields("VendorKey").value
If MandatoryFlags(i) = "Y" Then ManCount += 1 If VendorKey(i) = "Y" Then VenCount += 1
rstFields.close()

.

Nov 19 '05 #2
Andy,

Not a problem. Actually, if you really want to get a handle on VB.NET vs
VB6, read a book by Dan Appleman, *amazon link below*. One, its really
easy reading, I read it in 2 and a half days because I couldn't put it down.
But I'm a super nerd.

It will show you some understanding of how it all comes together.
Especially moving from ADO 2.5+ to ADOX (the .NET ADO). Which is COMPLETLY
different than ADO 2.7. It will throw you off at first. But make sure you
understand datasets, and once you do, you will be like "Wow... I've wanted
that for years!"

Also, if you write Dan, he responds to you in a short time. Really nice guy
too.

Good luck and let me know if you need anything else.

-CJ

http://www.amazon.com/exec/obidos/tg...books&n=507846
"Andy Barber" <An****@blueyonder.co.uk> wrote in message
news:05****************************@phx.gbl...
Thanks CJ.

Been so used to coding ASP an VB didn't realise .net was
that different. Thansks for the namespace pointer I can
go dig around.

Andy
-----Original Message-----

This looks like VB6, in which case this is the wrong

board, but I'll throw
an answer your way. And if its Not VB6, and this is how

your coding .NET...
go buy a book. Becuase this is bad. Really bad...

Don't take that offensivly, but your late binding (if

binding a datatype at
all to everything)

First of all, if you get a Object null error (not set to

instance) you have
to use the new constructor. And since you didn't tell us

where exactly it
was bombing, I could see about 8 places it would.

for example, dont declare something without a datatype.

(Dim rstFileds)

do

Dim rstFields as ADODB.Recordset.

Second of all, if this is .NET code, then don't use

ADODB. Use the
System.data namespace.

If you don't know what that is...

put it back in the box, and buy a book... then you may

have it back.

-CJ

"Andy Barber" <an****@blueyonder.co.uk> wrote in message
news:05****************************@phx.gbl...
Hi,

I'm trying to write an app that reads data from a table
into a string variable for later use in my program.
Below is a snippet of the code I'm using, which compiles
ok, but at runtime I get and error 'Object reference not
set to an instance of an object.' as soon as I try to
access the data in the fields, I.e. at the line that
reads 'KeyFlags(i) = rstFields("keyflag").value'

Anyone tell me where I'm going wrong?

strSQL = "SELECT fieldname, keyflag,
mandatoryflag ,vendorKey,tablename from field_relates "
strSQL = strSQL & "where fieldname = '" &
Remove_Quotes(namearray(i)) & "' AND tablename = '" &
CmdArgs(0) & "'"
Dim rstFields
rstFields = CreateObject("ADODB.Recordset")
rstFields.open(strSQL, strConn)
If rstFields.eof Then
MsgBox("**Error:- Field name " & namearray (i) & " not registered for " & CmdArgs(0) & " load at
position " & i + 1)
FileClose(1)
Return 4
End If
KeyFlags(i) = rstFields("keyflag").value
MandatoryFlags(i) = rstFields
("mandatoryflag").value
VendorKey(i) = rstFields("VendorKey").value
If MandatoryFlags(i) = "Y" Then ManCount += 1 If VendorKey(i) = "Y" Then VenCount += 1
rstFields.close()

.

Nov 19 '05 #3
Thanks for Link CJ, Will look int tordering it.

Maybe you can tell me if I'm using the right tools to do
this job, this Is wat I have..

A CSV data file with column headings in the first row.
These cloum headings to be validated against data in a
reference table on an SQLServer database.

Data from the CSV file is to be validated and inserted
into relevant tables on the SQLServer database.

Errors to be output to a log file. No user interface.

I thought I could use a console app to do this. Am I
right?

Andy
-----Original Message-----
Andy,

Not a problem. Actually, if you really want to get a handle on VB.NET vsVB6, read a book by Dan Appleman, *amazon link below*. One, its reallyeasy reading, I read it in 2 and a half days because I couldn't put it down.But I'm a super nerd.

It will show you some understanding of how it all comes together.Especially moving from ADO 2.5+ to ADOX (the .NET ADO). Which is COMPLETLYdifferent than ADO 2.7. It will throw you off at first. But make sure youunderstand datasets, and once you do, you will be like "Wow... I've wantedthat for years!"

Also, if you write Dan, he responds to you in a short time. Really nice guytoo.

Good luck and let me know if you need anything else.

-CJ

http://www.amazon.com/exec/obidos/tg/detail/- /159059102X/qid=1061473579/sr=8-3/ref=sr_8_3/002-9246455-
0548054?v=glance&s=books&n=507846

"Andy Barber" <An****@blueyonder.co.uk> wrote in message
news:05****************************@phx.gbl...
Thanks CJ.

Been so used to coding ASP an VB didn't realise .net was
that different. Thansks for the namespace pointer I can
go dig around.

Andy
>-----Original Message-----
>
>This looks like VB6, in which case this is the wrong

board, but I'll throw
>an answer your way. And if its Not VB6, and this is how
your coding .NET...
>go buy a book. Becuase this is bad. Really bad...
>
>Don't take that offensivly, but your late binding (if

binding a datatype at
>all to everything)
>
>First of all, if you get a Object null error (not set
to instance) you have
>to use the new constructor. And since you didn't tell
us where exactly it
>was bombing, I could see about 8 places it would.
>
>for example, dont declare something without a datatype.

(Dim rstFileds)
>
>do
>
>Dim rstFields as ADODB.Recordset.
>
>Second of all, if this is .NET code, then don't use

ADODB. Use the
>System.data namespace.
>
>If you don't know what that is...
>
>put it back in the box, and buy a book... then you may

have it back.
>
>-CJ
>
>"Andy Barber" <an****@blueyonder.co.uk> wrote in
message >news:05****************************@phx.gbl...
>> Hi,
>>
>> I'm trying to write an app that reads data from a table >> into a string variable for later use in my program.
>> Below is a snippet of the code I'm using, which compiles >> ok, but at runtime I get and error 'Object reference not >> set to an instance of an object.' as soon as I try to
>> access the data in the fields, I.e. at the line that
>> reads 'KeyFlags(i) = rstFields("keyflag").value'
>>
>> Anyone tell me where I'm going wrong?
>>
>> strSQL = "SELECT fieldname, keyflag,
>> mandatoryflag ,vendorKey,tablename from field_relates " >> strSQL = strSQL & "where fieldname = '" &
>> Remove_Quotes(namearray(i)) & "' AND tablename = '" &
>> CmdArgs(0) & "'"
>> Dim rstFields
>> rstFields = CreateObject ("ADODB.Recordset") >> rstFields.open(strSQL, strConn)
>> If rstFields.eof Then
>> MsgBox("**Error:- Field name " &

namearray
>> (i) & " not registered for " & CmdArgs(0) & " load at
>> position " & i + 1)
>> FileClose(1)
>> Return 4
>> End If
>> KeyFlags(i) = rstFields("keyflag").value
>> MandatoryFlags(i) = rstFields
>> ("mandatoryflag").value
>> VendorKey(i) = rstFields ("VendorKey").value >> If MandatoryFlags(i) = "Y" Then ManCount

+= 1
>> If VendorKey(i) = "Y" Then VenCount += 1
>> rstFields.close()
>>
>>
>>
>
>
>.
>

.

Nov 19 '05 #4
Andy,
Thanks for Link CJ, Will look int tordering it.

Maybe you can tell me if I'm using the right tools to do
this job, this Is wat I have..

A CSV data file with column headings in the first row.
These cloum headings to be validated against data in a
reference table on an SQLServer database.

Make your life simple, use the ASCII ODBC driver to read CSV's. you'll
shorten the amount of code you have to write. And then you can just cross
datasets.

Data from the CSV file is to be validated and inserted
into relevant tables on the SQLServer database.

using XML datasets you can validate. little more work when you enforce
constraints, but thats ok. well worth it and takes care of all the GIGO for
you. (You have to do some work, but not a lot in comparison to what you
WOULD do to check integrity of your data.
Errors to be output to a log file. No user interface.

I thought I could use a console app to do this. Am I
right?
Console app is fine, windows app is fine. doens't really matter. You can
have a windows application that has no windows interface, just has a Sub
Main(). You can set that in your project properties, it will take care of
the rest.
Andy
-----Original Message-----
Andy,

Not a problem. Actually, if you really want to get a

handle on VB.NET vs
VB6, read a book by Dan Appleman, *amazon link below*.

One, its really
easy reading, I read it in 2 and a half days because I

couldn't put it down.
But I'm a super nerd.

It will show you some understanding of how it all comes

together.
Especially moving from ADO 2.5+ to ADOX (the .NET ADO).

Which is COMPLETLY
different than ADO 2.7. It will throw you off at first.

But make sure you
understand datasets, and once you do, you will be

like "Wow... I've wanted
that for years!"

Also, if you write Dan, he responds to you in a short

time. Really nice guy
too.

Good luck and let me know if you need anything else.

-CJ

http://www.amazon.com/exec/obidos/tg/detail/-

/159059102X/qid=1061473579/sr=8-3/ref=sr_8_3/002-9246455-
0548054?v=glance&s=books&n=507846


"Andy Barber" <An****@blueyonder.co.uk> wrote in message
news:05****************************@phx.gbl...
Thanks CJ.

Been so used to coding ASP an VB didn't realise .net was
that different. Thansks for the namespace pointer I can
go dig around.

Andy
>-----Original Message-----
>
>This looks like VB6, in which case this is the wrong
board, but I'll throw
>an answer your way. And if its Not VB6, and this is how your coding .NET...
>go buy a book. Becuase this is bad. Really bad...
>
>Don't take that offensivly, but your late binding (if
binding a datatype at
>all to everything)
>
>First of all, if you get a Object null error (not set to instance) you have
>to use the new constructor. And since you didn't tell us where exactly it
>was bombing, I could see about 8 places it would.
>
>for example, dont declare something without a datatype.
(Dim rstFileds)
>
>do
>
>Dim rstFields as ADODB.Recordset.
>
>Second of all, if this is .NET code, then don't use
ADODB. Use the
>System.data namespace.
>
>If you don't know what that is...
>
>put it back in the box, and buy a book... then you may
have it back.
>
>-CJ
>
>"Andy Barber" <an****@blueyonder.co.uk> wrote in message >news:05****************************@phx.gbl...
>> Hi,
>>
>> I'm trying to write an app that reads data from a table >> into a string variable for later use in my program.
>> Below is a snippet of the code I'm using, which compiles >> ok, but at runtime I get and error 'Object reference not >> set to an instance of an object.' as soon as I try to
>> access the data in the fields, I.e. at the line that
>> reads 'KeyFlags(i) = rstFields("keyflag").value'
>>
>> Anyone tell me where I'm going wrong?
>>
>> strSQL = "SELECT fieldname, keyflag,
>> mandatoryflag ,vendorKey,tablename from field_relates " >> strSQL = strSQL & "where fieldname = '" &
>> Remove_Quotes(namearray(i)) & "' AND tablename = '" &
>> CmdArgs(0) & "'"
>> Dim rstFields
>> rstFields = CreateObject ("ADODB.Recordset") >> rstFields.open(strSQL, strConn)
>> If rstFields.eof Then
>> MsgBox("**Error:- Field name " &
namearray
>> (i) & " not registered for " & CmdArgs(0) & " load at
>> position " & i + 1)
>> FileClose(1)
>> Return 4
>> End If
>> KeyFlags(i) = rstFields("keyflag").value
>> MandatoryFlags(i) = rstFields
>> ("mandatoryflag").value
>> VendorKey(i) = rstFields ("VendorKey").value >> If MandatoryFlags(i) = "Y" Then ManCount += 1
>> If VendorKey(i) = "Y" Then VenCount += 1
>> rstFields.close()
>>
>>
>>
>
>
>.
>

.

Nov 19 '05 #5
Arrrg.

Wanted to use ODBC to start with since I have ODBC
connections to both the dabase and the flat files, but
couldn't get it to work.
Do you know of anywhere I can find some simple samples,
that DON'T use forms, that will set up an odbc link, read
data into variable and write daa back to link?
I've ordered the book, just hope it arrives firly quickly

Your help is MUCH appreciated, I think I've thrown myself
into the deep end here and am swimming under water, but
don't knw which direction the surface is:)

Andy
-----Original Message-----
Andy,
Thanks for Link CJ, Will look int tordering it.

Maybe you can tell me if I'm using the right tools to do this job, this Is wat I have..

A CSV data file with column headings in the first row.
These cloum headings to be validated against data in a
reference table on an SQLServer database.

Make your life simple, use the ASCII ODBC driver to read

CSV's. you'llshorten the amount of code you have to write. And then you can just crossdatasets.

Data from the CSV file is to be validated and inserted
into relevant tables on the SQLServer database.

using XML datasets you can validate. little more work

when you enforceconstraints, but thats ok. well worth it and takes care of all the GIGO foryou. (You have to do some work, but not a lot in comparison to what youWOULD do to check integrity of your data.
Errors to be output to a log file. No user interface.

I thought I could use a console app to do this. Am I
right?
Console app is fine, windows app is fine. doens't really

matter. You canhave a windows application that has no windows interface, just has a SubMain(). You can set that in your project properties, it will take care ofthe rest.
Andy
>-----Original Message-----
>Andy,
>
>Not a problem. Actually, if you really want to get a

handle on VB.NET vs
>VB6, read a book by Dan Appleman, *amazon link below*.

One, its really
>easy reading, I read it in 2 and a half days because I

couldn't put it down.
>But I'm a super nerd.
>
>It will show you some understanding of how it all comes

together.
>Especially moving from ADO 2.5+ to ADOX (the .NET ADO).

Which is COMPLETLY
>different than ADO 2.7. It will throw you off at first.
But make sure you
>understand datasets, and once you do, you will be

like "Wow... I've wanted
>that for years!"
>
>Also, if you write Dan, he responds to you in a short

time. Really nice guy
>too.
>
>Good luck and let me know if you need anything else.
>
>-CJ
>
>http://www.amazon.com/exec/obidos/tg/detail/-

/159059102X/qid=1061473579/sr=8-3/ref=sr_8_3/002- 9246455- 0548054?v=glance&s=books&n=507846
>
>
>"Andy Barber" <An****@blueyonder.co.uk> wrote in
message >news:05****************************@phx.gbl...
>> Thanks CJ.
>>
>> Been so used to coding ASP an VB didn't realise .net was >> that different. Thansks for the namespace pointer I can >> go dig around.
>>
>> Andy
>> >-----Original Message-----
>> >
>> >This looks like VB6, in which case this is the wrong
>> board, but I'll throw
>> >an answer your way. And if its Not VB6, and this is

how
>> your coding .NET...
>> >go buy a book. Becuase this is bad. Really bad...
>> >
>> >Don't take that offensivly, but your late binding (if >> binding a datatype at
>> >all to everything)
>> >
>> >First of all, if you get a Object null error (not set to
>> instance) you have
>> >to use the new constructor. And since you didn't
tell us
>> where exactly it
>> >was bombing, I could see about 8 places it would.
>> >
>> >for example, dont declare something without a
datatype. >> (Dim rstFileds)
>> >
>> >do
>> >
>> >Dim rstFields as ADODB.Recordset.
>> >
>> >Second of all, if this is .NET code, then don't use
>> ADODB. Use the
>> >System.data namespace.
>> >
>> >If you don't know what that is...
>> >
>> >put it back in the box, and buy a book... then you may >> have it back.
>> >
>> >-CJ
>> >
>> >"Andy Barber" <an****@blueyonder.co.uk> wrote in

message
>> >news:05****************************@phx.gbl...
>> >> Hi,
>> >>
>> >> I'm trying to write an app that reads data from a

table
>> >> into a string variable for later use in my program. >> >> Below is a snippet of the code I'm using, which

compiles
>> >> ok, but at runtime I get and error 'Object reference not
>> >> set to an instance of an object.' as soon as I
try to >> >> access the data in the fields, I.e. at the line that >> >> reads 'KeyFlags(i) = rstFields("keyflag").value'
>> >>
>> >> Anyone tell me where I'm going wrong?
>> >>
>> >> strSQL = "SELECT fieldname, keyflag,
>> >> mandatoryflag ,vendorKey,tablename from

field_relates "
>> >> strSQL = strSQL & "where fieldname = '" & >> >> Remove_Quotes(namearray(i)) & "' AND tablename = '" & >> >> CmdArgs(0) & "'"
>> >> Dim rstFields
>> >> rstFields = CreateObject

("ADODB.Recordset")
>> >> rstFields.open(strSQL, strConn)
>> >> If rstFields.eof Then
>> >> MsgBox("**Error:- Field name " &
>> namearray
>> >> (i) & " not registered for " & CmdArgs(0) & " load at >> >> position " & i + 1)
>> >> FileClose(1)
>> >> Return 4
>> >> End If
>> >> KeyFlags(i) = rstFields ("keyflag").value >> >> MandatoryFlags(i) = rstFields
>> >> ("mandatoryflag").value
>> >> VendorKey(i) = rstFields

("VendorKey").value
>> >> If MandatoryFlags(i) = "Y" Then ManCount +=
>> 1
>> >> If VendorKey(i) = "Y" Then VenCount

+= 1 >> >> rstFields.close()
>> >>
>> >>
>> >>
>> >
>> >
>> >.
>> >
>
>
>.
>

.

Nov 19 '05 #6
Andy,

Alright, First of all, I'm assuming your using VS.NET 2002. Just because
you don't have the drag and drop ODBC drivers from MS. (the first ones that
came out sucked).

As for samples, you can always use Planet Source Code
(www.planetsourcecode.com), there is some good stuff there. As for using
ODBC for both, I would advise agsint it, just because the OLEDB drivers for
SQL server are really really good. =) I like em at least, but I'm sure
someone has SOME problem with them. but so far they have done everything I
wanted.

Here is what you have to remember about VB -> VB.NET. Ok, you remember how
you have teh form designer in VB6? Well, you have that, but it creates
objects in the code behind (Look at the region Windows Form Designer
Generated code or something).

So, the IDE is just there to make it simple, but you can code VB.NET forms
without an IDE (though it would be long and tiresome, like watching Legally
Blonde 2).

So. you can have a form, with nothing on it if you want. (if you want to
save some steps and headaches of already switching to a language called VB,
but honestly it isn't VB. VB.NET is nothing like VB6, except for Dim, Sub
and Function. =) )

If you have 2003, then you have the ODBC drivers already there. That saves
time.

Also, most important thing you can ever take from me is this. Everything is
an object. If you can understand that, you can understand .NET.

As far as throwing yourself into the deep and and trying to swim... Yeah,
you did. But ask yourself this. How else are you going to learn it?
Taking a college extension course over the next 9 months learning how to
write a friggin single form app (because most college professors don't
understand the difference between MDI forms and other. Don't even get me
start on Event handlers with them.)

I'm always happy to help out too.. feel free to email if you want. I just
post here so everyone can benefit. I was in the same position (I had a java
background though) in which case I looked at VB.NET and said "What the f***
is this?"

Take care,
CJ
Arrrg.

Wanted to use ODBC to start with since I have ODBC
connections to both the dabase and the flat files, but
couldn't get it to work.
Do you know of anywhere I can find some simple samples,
that DON'T use forms, that will set up an odbc link, read
data into variable and write daa back to link?
I've ordered the book, just hope it arrives firly quickly

Your help is MUCH appreciated, I think I've thrown myself
into the deep end here and am swimming under water, but
don't knw which direction the surface is:)

Andy
-----Original Message-----
Andy,
Thanks for Link CJ, Will look int tordering it.

Maybe you can tell me if I'm using the right tools to do this job, this Is wat I have..

A CSV data file with column headings in the first row.
These cloum headings to be validated against data in a
reference table on an SQLServer database.


Make your life simple, use the ASCII ODBC driver to read

CSV's. you'll
shorten the amount of code you have to write. And then

you can just cross
datasets.

Data from the CSV file is to be validated and inserted
into relevant tables on the SQLServer database.


using XML datasets you can validate. little more work

when you enforce
constraints, but thats ok. well worth it and takes care

of all the GIGO for
you. (You have to do some work, but not a lot in

comparison to what you
WOULD do to check integrity of your data.
Errors to be output to a log file. No user interface.

I thought I could use a console app to do this. Am I
right?

Console app is fine, windows app is fine. doens't really

matter. You can
have a windows application that has no windows interface,

just has a Sub
Main(). You can set that in your project properties, it

will take care of
the rest.
Andy
>-----Original Message-----
>Andy,
>
>Not a problem. Actually, if you really want to get a
handle on VB.NET vs
>VB6, read a book by Dan Appleman, *amazon link below*.
One, its really
>easy reading, I read it in 2 and a half days because I
couldn't put it down.
>But I'm a super nerd.
>
>It will show you some understanding of how it all comes
together.
>Especially moving from ADO 2.5+ to ADOX (the .NET ADO).
Which is COMPLETLY
>different than ADO 2.7. It will throw you off at first. But make sure you
>understand datasets, and once you do, you will be
like "Wow... I've wanted
>that for years!"
>
>Also, if you write Dan, he responds to you in a short
time. Really nice guy
>too.
>
>Good luck and let me know if you need anything else.
>
>-CJ
>
>http://www.amazon.com/exec/obidos/tg/detail/-
/159059102X/qid=1061473579/sr=8-3/ref=sr_8_3/002- 9246455- 0548054?v=glance&s=books&n=507846
>
>
>"Andy Barber" <An****@blueyonder.co.uk> wrote in message >news:05****************************@phx.gbl...
>> Thanks CJ.
>>
>> Been so used to coding ASP an VB didn't realise .net was >> that different. Thansks for the namespace pointer I can >> go dig around.
>>
>> Andy
>> >-----Original Message-----
>> >
>> >This looks like VB6, in which case this is the wrong
>> board, but I'll throw
>> >an answer your way. And if its Not VB6, and this is
how
>> your coding .NET...
>> >go buy a book. Becuase this is bad. Really bad...
>> >
>> >Don't take that offensivly, but your late binding (if >> binding a datatype at
>> >all to everything)
>> >
>> >First of all, if you get a Object null error (not set to
>> instance) you have
>> >to use the new constructor. And since you didn't tell us
>> where exactly it
>> >was bombing, I could see about 8 places it would.
>> >
>> >for example, dont declare something without a datatype. >> (Dim rstFileds)
>> >
>> >do
>> >
>> >Dim rstFields as ADODB.Recordset.
>> >
>> >Second of all, if this is .NET code, then don't use
>> ADODB. Use the
>> >System.data namespace.
>> >
>> >If you don't know what that is...
>> >
>> >put it back in the box, and buy a book... then you may >> have it back.
>> >
>> >-CJ
>> >
>> >"Andy Barber" <an****@blueyonder.co.uk> wrote in
message
>> >news:05****************************@phx.gbl...
>> >> Hi,
>> >>
>> >> I'm trying to write an app that reads data from a
table
>> >> into a string variable for later use in my program. >> >> Below is a snippet of the code I'm using, which
compiles
>> >> ok, but at runtime I get and error 'Object reference not
>> >> set to an instance of an object.' as soon as I try to >> >> access the data in the fields, I.e. at the line that >> >> reads 'KeyFlags(i) = rstFields("keyflag").value'
>> >>
>> >> Anyone tell me where I'm going wrong?
>> >>
>> >> strSQL = "SELECT fieldname, keyflag,
>> >> mandatoryflag ,vendorKey,tablename from
field_relates "
>> >> strSQL = strSQL & "where fieldname = '" & >> >> Remove_Quotes(namearray(i)) & "' AND tablename = '" & >> >> CmdArgs(0) & "'"
>> >> Dim rstFields
>> >> rstFields = CreateObject
("ADODB.Recordset")
>> >> rstFields.open(strSQL, strConn)
>> >> If rstFields.eof Then
>> >> MsgBox("**Error:- Field name " &
>> namearray
>> >> (i) & " not registered for " & CmdArgs(0) & " load at >> >> position " & i + 1)
>> >> FileClose(1)
>> >> Return 4
>> >> End If
>> >> KeyFlags(i) = rstFields ("keyflag").value >> >> MandatoryFlags(i) = rstFields
>> >> ("mandatoryflag").value
>> >> VendorKey(i) = rstFields
("VendorKey").value
>> >> If MandatoryFlags(i) = "Y" Then ManCount +=
>> 1
>> >> If VendorKey(i) = "Y" Then VenCount += 1 >> >> rstFields.close()
>> >>
>> >>
>> >>
>> >
>> >
>> >.
>> >
>
>
>.
>

.

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Randi | last post by:
Hi all, I have this project to use the ADODB control to acces and manipulate the Access DB. I amd the mistake of first doing this project with just the data control. It worked fine with this...
5
by: T. Wintershoven | last post by:
Hello, Although i write programs in VB for a while now, i've allways used the datacontrol and MS-Access DBs for data storage and never (and i mean never) used SQL. I lookt in many sample...
1
by: Robertb | last post by:
I'm driving myself crazy trying to figure this one out. So much so that I think I'm within walking distance now! The program is written and compiled in Visual Basic 6 with SP5. The OS is...
0
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
0
by: Channing Jones | last post by:
Hello everyone, I am trying to store data in a binary field of an SQL-Server table using ADODB. So far, I have managed to store a record but not any data in the binary field. I only get...
2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
4
by: nick_faye | last post by:
hi guys, hope somebody can assist me. i have two ms access database. i have to copy the entries in database1 to my database2. however, i have to copy entries from database1 that does not...
0
by: lewang | last post by:
I am trying to get data from Access through a SQL query from Excel via VBA: but i get an error of "Run Time Error '-2147467259 (800040005)': Method 'Open' of object '_Recordset' failed" I have...
3
by: | last post by:
Hello ppl, I have snippet that works fine udner ADODB with VB6, but something wrong with it in Vb.NET. Anyone can help? Recordset1 (ADODB.Recordset) Error: Arguments are of the wrong type, are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.