Accessing data from a ADODB.recordset

A

Andy Barber

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()
 
A

Andy Barber

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
 
C

CJ Taylor

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/t...002-9246455-0548054?v=glance&s=books&n=507846
 
A

Andy Barber

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
 
C

CJ Taylor

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.
 
A

Andy Barber

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
 
C

CJ Taylor

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
 

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

Similar Threads


Top