473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help inserting Records

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
2 958
objDataSet.Tables("EligibilityResponse")

must not return an actual table..I don't see anywhere tha tyou (a) fill the
dataset or/and (b) add a table to it and name it that...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Brian Ciarcia" <bc******@pepehazard.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2
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..

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sparrow | last post by:
I have created a table with the following columns... Date(datetime),Actual (Int),Planned (Int) I need to insert weekending dates starting from 23/04/04 looping thru'for the next 52weeks...
3
by: Rich | last post by:
This is what one of the tables looks like - they are all similar and there are about 60 different tables: CREATE TABLE SalesData1( smalldatetime TimeStamp, varchar(8) CustomerID, numeric S1,...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
6
by: Pushpendra Vats | last post by:
Hi , I am trying to insert records into database. I am trying to write the following code. On button1 click event i am inserting five records and after that i am calling the update method of...
15
by: Jaraba | last post by:
I am working in a project that I need to parse an arrayt an select records based upon the values parsed. I used the functions developed by Knut Stolze in his article 'Parsing Strings'. I am...
9
by: dan | last post by:
within a loop i am building a sql insert statement to run against my (programatically created) mdb. it works but it seems unreasonably SLOW! Sorry, dont have the code here but the jist is very...
0
by: LiamLiamLiam | last post by:
G'day all. I having a problem with my formview. I'll ty to explain my situation as best as i can. I have a page with a search field at the top which is just a simple asp:textbox. Below that i...
4
memoman
by: memoman | last post by:
Can any body help me in that program ??? mail me if anybody could reach any -helpfull- thing Write a C++ program that namely insert, delete, and search in a fixed record length file (containing...
6
by: pompeyoc | last post by:
Hi! We are having problems with an SQL stored proc that uses Global Temporary Tables. The SP creates the GTT as follows: DECLARE GLOBAL TEMPORARY TABLE TEMP_ENTRIES (field1, field2, etc) ON...
5
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.