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