473,413 Members | 1,989 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,413 software developers and data experts.

need help:unable add records with OLEDB

Sub Button1_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=" & server.mappath("EzySys.mdb") & ";"
Dim myConn As New OleDbConnection(ConnectionString)
Dim myDataAdapter As New OleDbDataAdapter()
dim mySQL = "select * from resident_info"
myDataAdapter.SelectCommand = New OleDbCommand(mySQL, myConn)
Dim custCB As OleDbCommandBuilder = New
OleDbCommandBuilder(MyDataAdapter)

myConn.Open()

Dim DS As DataSet = New DataSet
myDataAdapter.Fill(DS)
Dim table As DataTable
Dim newRow As DataRow

' Code to modify data in DataSet here
table=DS.Tables("Resident_Info")
newRow=table.NewRow()
newRow("Resident_ID")="SL100"
table.Rows.add(newRow)
myConn.Close()
End Sub


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Nov 21 '05 #1
1 976
Chriz,

I made your code more simple. Know that the table names and everything
between quotes what comes from SQL is case sensitive, that was probably your
error. However see all the changes I made here in this message (so watch
typos)

Know that this sub has no sense at all, a webpage is stateless, what means
that you read a database add a new record to a datatable and than all
information is gone when the sub ends and the page on the client side is
refreshed.

\\\
Sub Button1_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=" & server.mappath("EzySys.mdb") & ";"
Dim myConn As New OleDbConnection(ConnectionString)
dim mySQL = "select * from resident_info"
Dim myDataAdapter As New OleDbDataAdapter(mySQL, myConn)
Try
myConn.Open()
Dim DS As DataSet = New DataSet
myDataAdapter.Fill(DS)
catch ex as exception
me.myfield = ex.tostring 'a label on your form somewhere to test
exit sub
finally
myConn.close
end try
Dim custCB As OleDbCommandBuilder = New
OleDbCommandBuilder(MyDataAdapter)
Dim table As DataTable
Dim newRow As DataRow
' Code to modify data in DataSet here
table=DS.Tables(0)
newRow=table.NewRow()
newRow("Resident_ID")="SL100"
table.Rows.add(newRow)
End Sub
///

I hope this helps something?

Cor
Nov 21 '05 #2

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

Similar topics

2
by: Ryan Wagner | last post by:
I am doing many SQL insert statements to insert records into an oracle database. I need the order of the records, after inserting all records, to be the same as the order I inserted them in. Right...
0
by: mkent | last post by:
I have a vexing problem and seek some input on how to fix it. Starting with Python 2.4.0, I have been unable to compile a working Python on our AIX 4.3.3 development system. I can compile a...
0
by: archana | last post by:
Iam unable to run a macro from visual basic... The code does not work when the ms access database(any database ) is open... HELP! Dim strDbName As String Dim strlvsendkeys As String Dim...
7
by: Axel Dahmen | last post by:
I've just installed Windows 2000 Service Pack 4 (SP4) on my Windows 2000 Server. Now I can't debug anymore! I'm using Visual Studio 7.0 (2002), ..NET Framework 1.0. The error message I get is...
2
by: Ddraig | last post by:
Howdy, I've been struggling with this most of the day and I was wondering if anyone has seen this before and can point me in the direction for a solution. My program runs perfectly, however...
1
by: Ddraig | last post by:
Howdy, I've been struggling with this most of the day and I was wondering if anyone has seen this before and can point me in the direction for a solution. My program runs perfectly, however...
1
by: beatlebum | last post by:
I am building a web application using VS 2003 in c#. I am able to successfully add a web reference. However when I attempt to 'use' it, I get an error message saying: 'The type or namespace...
3
by: keithb | last post by:
What could be causing this? this code: String Com = ""; if (Com != (String)rw.ItemArray) fails at runtime with the error message: Unable to cast object of type 'System.Int32' to type...
0
by: =?Utf-8?B?dGVzaHRyYWRlQGdtYWlsLmNvbQ==?= | last post by:
Hi All, I am still new to Webservices in .NET Basically, This is what I am trying to accomplish. My Client has given me the soft copy of the WSDL file and XSD Files and has asked me to create...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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...
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,...
0
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...

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.