Problem With DataAdapter

  • Thread starter Thread starter Wayne Wengert
  • Start date Start date
W

Wayne Wengert

I am trying to fill a dataset with a list of user tables from an Access
database. When I run the code (below) I get an error on the myDA1.Fill line.
The error message is: "Value cannot be null".

If I copy and paste the SQL string into an Access query it works fine. The
connection string is valid (used in another case).

Any thoughts on what might cause this.

====================================
Dim myDS1 As DataSet

Dim row As DataRow

Dim strTemp As String

strTemp = "SELECT MSysObjects.Name FROM MSysObjects WHERE " & _

" (((MSysObjects.Name) Not Like 'MSys%') AND " & _

" ((MSysObjects.Type)=1)) ORDER BY MSysObjects.Name"

Dim myDA1 As New OleDb.OleDbDataAdapter(strTemp, mConnStr)

Dim ii As Integer = 0

myDA1.Fill(myDS1, "AllTables")
 
It sounds like there is a field in your table in your
dataset which does not allow nulls. You can retrieve the
records from the database but you cannot insert them into
your dataset table because of this. If this is the case
you would be able to run the query in access or sql with
no problems but not fill your dataset. You will need to
modify your dataset table to allow nulls for the field
causing the error.

If you look in the vb code generated for your dataset you
will find an InitClass() sub. In here is where you set
which columns you want to allow dbnull.

Change it to say:
Me.Column??.AllowDBNull = True

Hope this helps,

Billy Jacobs
 
Hello Wayne,

Thanks for your post.
From your code snippet, you declared a DataSet variable without creating a
new instance of the DataSet. If so, I believe the exception is caused by
it, and you should instanciate DataSet:

Dim myDS1 As DataSet
myDS1 = new DataSet()

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
Thanks. I still am very confused with the wonderful world of OO - when to
Dim, when to use "New", etc. etc.

I'll try the change you suggest

Wayne
 
Hello Wayne,

I am very glad to hear that the problem was resolved!

In addition, I recommend you the following documentation on Visual Basic
"New" expression:
Visual Basic Language Specification: 9.6 New Expressions
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbls7/html/
vblrfVBSpec9_6.asp?frame=true

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
Back
Top