Our forums are currently in maintenance mode and the ability to post is disabled. We will be back up and running as soon as possible. Thanks for your patience!



Object reference not set to an instance of an object.

By jazzygodfrey ·
hi, I am trying to insert data into db using dataset already loaded with data from another source and here is my code;

Dim InsertSQL As String
InsertSQL = "INSERT INTO AccessToSQL (checkno , votecode, member_amount, employer_amount, paydate, basicpay, sal_scale) " & _
" VALUES (@checkno , @votecode, @member_amount, @employer_amount, @paydate, @basicpay, @sal_scale)"

Dim dr As DataRow
'here is where the error comes
For Each dr In UploadDataSet.Tables("Tablename").Rows

Dim sqlcomm As New SqlCommand(InsertSQL, DestConnection)

sqlcomm.Parameters.AddWithValue("@checkno", dr.Item("checkno").ToString)
sqlcomm.Parameters.AddWithValue("@votecode", dr("votecode").ToString)
sqlcomm.Parameters.AddWithValue("@member_amount", dr("member_amount").ToString)
sqlcomm.Parameters.AddWithValue("@employer_amount", dr("employer_amount").ToString)

and so on......

i get the error in the loop, I have tried to dim dr as new datarow I get another error saying " not accessible because it is protected"

I would appreciate any help

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Do you really have a table called Tablename?

by Tony Hopkinson In reply to Object reference not set ...

Put a debug on the line and then make sure
UploadDataset isn't null, that it has a non null Tables collections and that in there there is a table called "Tablename".

One suspects not.

Collapse -

Thanks Tony!!

by jazzygodfrey In reply to Do you really have a tab ...

thanks tony it took me a day to figure out what the problem was, actually UploadDataset was null because of the line 'For Each dr In UploadDataSet.Tables("TableName").Rows' Tablename is a variable that carries the table that the user selected my mistake was putting the "quotes" in the tablename, you saved my day thanks again!

Collapse -

You aren't the first one to make that mistake

by Tony Hopkinson In reply to Thanks Tony!!

wasn't me either....

Why an obect is null, can be hard to find, that it is, is indisputable.

Related Discussions

Related Forums