Object reference not set to an instance of an object. - TechRepublic
Question
January 8, 2010 at 02:03 AM
jazzygodfrey

Object reference not set to an instance of an object.

by jazzygodfrey . Updated 16 years, 6 months ago

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……
sqlcomm.ExecuteNonQuery()
Next

i get the error in the loop, I have tried to dim dr as new datarow I get another error saying “system.data.datarow.protected ….is not accessible because it is protected”

I would appreciate any help

This discussion is locked

All Comments