473,624 Members | 2,685 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("FirstN ame")
Dim LastName As String = Session("LastNa me")
Dim DOB As String = Session("DOB")
Dim ResponseDate As String = Now()
Dim SponsorCode As String = Session("Sponso rCode")
'Dim counter As Integer
' Dim arr() As String
' Dim coll As NameValueCollec tion

' coll = Request.Form

'arr = coll.AllKeys

'For counter = 0 To arr.GetUpperBou nd(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 = "__VIEWSTAT E") Or (answer = "Button1") Then
Else

Dim strConnection As String = Myconnection
Dim StrSQL As String = "Select ResponseID, ResponseDate,
LastName, FirstName, DOB, SponsorCode, QuestionID, QResponse from
EligibilityResp onse"
Dim objDataSet As New DataSet
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapte r
Dim objCommand As OleDbCommand
Dim objBuilder As OleDbCommandBui lder

objConnection = New OleDbConnection (strConnection)
objAdapter = New OleDbDataAdapte r(StrSQL, objConnection)
objBuilder = New OleDbCommandBui lder(objAdapter )

objAdapter.Inse rtCommand = objBuilder.GetI nsertCommand()

Dim objTable As DataTable
Dim objNewRow As DataRow

objTable = objDataSet.Tabl es("Eligibility Response")
objNewRow = objTable.NewRow ()
objNewRow("Resp onseDate") = ResponseDate
objNewRow("Last Name") = LastName
objNewRow("Firs tName") = FirstName
objNewRow("DOB" ) = DOB
objNewRow("Spon sorCode") = SponsorCode
objNewRow("Ques tionID") = answer
objNewRow("QRes ponse") = Request.Form(an swer)
objTable.Rows.A dd(objNewRow)
AnsStr = AnsStr & "the answer to question " & answer & "
is " & Request.Form(an swer) & " " & 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 972
objDataSet.Tabl es("Eligibility Response")

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******@pepeh azard.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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("FirstN ame")
Dim LastName As String = Session("LastNa me")
Dim DOB As String = Session("DOB")
Dim ResponseDate As String = Now()
Dim SponsorCode As String = Session("Sponso rCode")
'Dim counter As Integer
' Dim arr() As String
' Dim coll As NameValueCollec tion

' coll = Request.Form

'arr = coll.AllKeys

'For counter = 0 To arr.GetUpperBou nd(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 = "__VIEWSTAT E") Or (answer = "Button1") Then
Else

Dim strConnection As String = Myconnection
Dim StrSQL As String = "Select ResponseID, ResponseDate,
LastName, FirstName, DOB, SponsorCode, QuestionID, QResponse from
EligibilityResp onse"
Dim objDataSet As New DataSet
Dim objConnection As OleDbConnection
Dim objAdapter As OleDbDataAdapte r
Dim objCommand As OleDbCommand
Dim objBuilder As OleDbCommandBui lder

objConnection = New OleDbConnection (strConnection)
objAdapter = New OleDbDataAdapte r(StrSQL, objConnection)
objBuilder = New OleDbCommandBui lder(objAdapter )

objAdapter.Inse rtCommand = objBuilder.GetI nsertCommand()

Dim objTable As DataTable
Dim objNewRow As DataRow

objTable = objDataSet.Tabl es("Eligibility Response")
objNewRow = objTable.NewRow ()
objNewRow("Resp onseDate") = ResponseDate
objNewRow("Last Name") = LastName
objNewRow("Firs tName") = FirstName
objNewRow("DOB" ) = DOB
objNewRow("Spon sorCode") = SponsorCode
objNewRow("Ques tionID") = answer
objNewRow("QRes ponse") = Request.Form(an swer)
objTable.Rows.A dd(objNewRow)
AnsStr = AnsStr & "the answer to question " & answer & "
is " & Request.Form(an swer) & " " & 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
2063
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 automatically into the date column. Then in the actual and planned colums, I need to insert a count of some records in the table. I will appreciate help on a SQL query to achieve this!
3
2000
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, numeric S2, numeric S3, numeric S4,
9
4344
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 predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
6
2047
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 dataadapter to update the records in database. Records are inserting but all the five records have the same value and that too of that last ones.. More over i tried to use the acceptchanges methods for datatable and dataset but of no use
15
2898
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 particulary having problems inserting records using a function. I am attaching the code for your review. Please, help. =================================--Function 1--====================================
9
8665
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 standard (I think!); e.g: # get connection loop
0
2136
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 have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a formview for inserting and editing the records. when a user clicks on one of the records in the...
4
1903
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 a person’s name and age). Associated with the record file will be a file that stores a binary search tree index that allows for a quick search through the index. The required operations will be provided using an input file that will be specified...
6
2957
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 COMMIT PRESERVE ROWS NOT LOGGED IN TEMP_SPACE The table is then filled with records from other permanent tables using: INSERT INTO SESSION.TEMP_ENTRIES SELECT fields FROM table1, table2
5
2160
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. So here's my method. I created two tables with the same structure as the table I'm inserting from. One table, Split_Temp, is the one I'll be inserting to. The other table, Split_Insert, contains the "Blank" record, which actually just has the word...
0
8182
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8494
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.