By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Accessing data from a ADODB.recordset

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.