Help inserting Records

B

Brian Ciarcia

Can someone please take a look at this code and tell me what I am doing
wrong???

I am getting the following error:

----------------------------------------------------
Object reference not set to an instance of an object.
--------------------------------------------------
at this line:

---------------------------------------------------------
objNewRow = objTable.NewRow()
------------------------------------------------


Dim FirstName As String = Session("FirstName")
Dim LastName As String = Session("LastName")
Dim DOB As String = Session("DOB")
Dim ResponseDate As String = Now()
Dim SponsorCode As String = Session("SponsorCode")


'Dim counter As Integer
' Dim arr() As String
' Dim coll As NameValueCollection

' coll = Request.Form

'arr = coll.AllKeys

'For counter = 0 To arr.GetUpperBound(0)
'Response.Write("Form: " & arr(counter) & "<br>")
Dim answer As String
Dim AnsStr
For Each answer In Request.Form
'references to answer return the name of the item
If (answer = "__VIEWSTATE") Or (answer = "Button1") Then
Else

Dim strConnection As String = Myconnection
Dim StrSQL As String = "Select ResponseID, ResponseDate,
LastName, FirstName, DOB, SponsorCode, QuestionID, QResponse from
EligibilityResponse"
Dim objDataSet As New DataSet
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objCommand As OleDbCommand
Dim objBuilder As OleDbCommandBuilder

objConnection = New OleDbConnection(strConnection)
objAdapter = New OleDbDataAdapter(StrSQL, objConnection)
objBuilder = New OleDbCommandBuilder(objAdapter)

objAdapter.InsertCommand = objBuilder.GetInsertCommand()

Dim objTable As DataTable
Dim objNewRow As DataRow

objTable = objDataSet.Tables("EligibilityResponse")
objNewRow = objTable.NewRow()
objNewRow("ResponseDate") = ResponseDate
objNewRow("LastName") = LastName
objNewRow("FirstName") = FirstName
objNewRow("DOB") = DOB
objNewRow("SponsorCode") = SponsorCode
objNewRow("QuestionID") = answer
objNewRow("QResponse") = Request.Form(answer)
objTable.Rows.Add(objNewRow)


AnsStr = AnsStr & "the answer to question " & answer & "
is " & Request.Form(answer) & " " & FirstName & " " & LastName & " " &
DOB & " " & ResponseDate & " " & SponsorCode & " <br>"
End If
Next
Label1.Text = AnsStr
 
B

Brian Ciarcia

Karl,

Thanks for responding.. You are right.. I screwed up.. I was using some
sample code to insert some data and realized that wasn't the right code
I should be looking at.. I am all set now.. thanks alot..
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top