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

UpdateCommand

Hi Guys,

I am having problems getting the following code to update an Access table. I
get the following error:-

An unhandled exception of type 'System.NullReferenceException' occurred in
MemberBase.exe

Additional information: Object reference not set to an instance of an
object.
This is the code:-

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

Dim myconnection As Odbc.OdbcConnection
myconnection = New Odbc.OdbcConnection("DSN=memberbase")
Dim mysql As String
Dim myda As Odbc.OdbcDataAdapter

mysql = "UPDATE tblMembers SET LastName = 'Johnson' WHERE MemberID
= 6666"

Dim dsOutCmdBuild As New Odbc.OdbcCommandBuilder(myda)
dsOutCmdBuild.QuotePrefix = "["
dsOutCmdBuild.QuoteSuffix = "]"

Dim UpdateCommand = New Odbc.OdbcCommand(mysql, myconnection)
myda.UpdateCommand = UpdateCommand

myconnection.Open()

Dim custDS As DataSet = New DataSet
myda.Fill(custDS)

myda.Update(custDS)

myconnection.Close()

End Sub

The LastName and MemberID fields exist and I have a MemberID of 6666.

Any ideas as to what is wrong?

Thanks

Peter.

Nov 21 '05 #1
5 4588
First turn option strict on at the top of your page,
next i think this is the problem:

Dim myda As Odbc.OdbcDataAdapter
should be
Dim myda As New Odbc.OdbcDataAdapter

this is also wrong:
Dim UpdateCommand = New Odbc.OdbcCommand(mysql, myconnection)
should be
Dim UpdateCommand As New Odbc.OdbcCommand(mysql, myconnection)

hth Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Peter W Johnson" <vk****@yahoo.com> schreef in bericht
news:#J*************@tk2msftngp13.phx.gbl...
Hi Guys,

I am having problems getting the following code to update an Access table. I get the following error:-

An unhandled exception of type 'System.NullReferenceException' occurred in
MemberBase.exe

Additional information: Object reference not set to an instance of an
object.
This is the code:-

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

Dim myconnection As Odbc.OdbcConnection
myconnection = New Odbc.OdbcConnection("DSN=memberbase")
Dim mysql As String
Dim myda As Odbc.OdbcDataAdapter

mysql = "UPDATE tblMembers SET LastName = 'Johnson' WHERE MemberID = 6666"

Dim dsOutCmdBuild As New Odbc.OdbcCommandBuilder(myda)
dsOutCmdBuild.QuotePrefix = "["
dsOutCmdBuild.QuoteSuffix = "]"

Dim UpdateCommand = New Odbc.OdbcCommand(mysql, myconnection)
myda.UpdateCommand = UpdateCommand

myconnection.Open()

Dim custDS As DataSet = New DataSet
myda.Fill(custDS)

myda.Update(custDS)

myconnection.Close()

End Sub

The LastName and MemberID fields exist and I have a MemberID of 6666.

Any ideas as to what is wrong?

Thanks

Peter.

Nov 21 '05 #2
Peter,

In addition to Peter,

A commandbuilder builds from a select command an update, insert and a delete
command.

I don't see a select command however an Update command that you use in that.

Also do you not have to use a dataadapter (or a dataset) to use this update
command however only a command.

I hope this helps,

Cor
Nov 21 '05 #3
Peter,

Thanks. I amended the commands and now get a new error:-

An unhandled exception of type 'System.InvalidOperationException' occurred
in system.data.dll

Additional information: The SelectCommand property has not been initialized
before calling 'Fill'.

The error occurs at the "myda.Fill(custDS)" statement.

Any more ideas?

Cheers

Peter.

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:ua**************@TK2MSFTNGP14.phx.gbl...
First turn option strict on at the top of your page,
next i think this is the problem:

Dim myda As Odbc.OdbcDataAdapter
should be
Dim myda As New Odbc.OdbcDataAdapter

this is also wrong:
Dim UpdateCommand = New Odbc.OdbcCommand(mysql, myconnection)
should be
Dim UpdateCommand As New Odbc.OdbcCommand(mysql, myconnection)

hth Greetz Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Peter W Johnson" <vk****@yahoo.com> schreef in bericht
news:#J*************@tk2msftngp13.phx.gbl...
Hi Guys,

I am having problems getting the following code to update an Access
table.

I
get the following error:-

An unhandled exception of type 'System.NullReferenceException' occurred
in
MemberBase.exe

Additional information: Object reference not set to an instance of an
object.
This is the code:-

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

Dim myconnection As Odbc.OdbcConnection
myconnection = New Odbc.OdbcConnection("DSN=memberbase")
Dim mysql As String
Dim myda As Odbc.OdbcDataAdapter

mysql = "UPDATE tblMembers SET LastName = 'Johnson' WHERE

MemberID
= 6666"

Dim dsOutCmdBuild As New Odbc.OdbcCommandBuilder(myda)
dsOutCmdBuild.QuotePrefix = "["
dsOutCmdBuild.QuoteSuffix = "]"

Dim UpdateCommand = New Odbc.OdbcCommand(mysql, myconnection)
myda.UpdateCommand = UpdateCommand

myconnection.Open()

Dim custDS As DataSet = New DataSet
myda.Fill(custDS)

myda.Update(custDS)

myconnection.Close()

End Sub

The LastName and MemberID fields exist and I have a MemberID of 6666.

Any ideas as to what is wrong?

Thanks

Peter.


Nov 21 '05 #4
Thanks Guys,

I managed it by using this:-

Dim myconnection As New Odbc.OdbcConnection("DSN=memberbase")
myconnection.Open()

Dim mysql As String = "SELECT * from Members WHERE MemberID = 6666"
Dim dsUpdate As New DataSet

Dim daUpdate As Odbc.OdbcDataAdapter = New
Odbc.OdbcDataAdapter(mysql, myconnection)
Dim cmdBuilder As Odbc.OdbcCommandBuilder = New
Odbc.OdbcCommandBuilder(daUpdate)

daUpdate.Fill(dsUpdate)

dsUpdate.Tables(0).Rows(0)("LastName") = "Johnson"

' Update database with modified data
daUpdate.UpdateCommand = cmdBuilder.GetUpdateCommand()
daUpdate.Update(dsUpdate.Tables(0))

myconnection.Close()

All now working well.

Many thanks

Peter
Nov 21 '05 #5
Glad to see you got it working, I wasn't at work for a couple of hours
that's why I didn't respond.

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Peter W Johnson" <vk****@yahoo.com> schreef in bericht
news:eb**************@TK2MSFTNGP14.phx.gbl...
Thanks Guys,

I managed it by using this:-

Dim myconnection As New Odbc.OdbcConnection("DSN=memberbase")
myconnection.Open()

Dim mysql As String = "SELECT * from Members WHERE MemberID = 6666" Dim dsUpdate As New DataSet

Dim daUpdate As Odbc.OdbcDataAdapter = New
Odbc.OdbcDataAdapter(mysql, myconnection)
Dim cmdBuilder As Odbc.OdbcCommandBuilder = New
Odbc.OdbcCommandBuilder(daUpdate)

daUpdate.Fill(dsUpdate)

dsUpdate.Tables(0).Rows(0)("LastName") = "Johnson"

' Update database with modified data
daUpdate.UpdateCommand = cmdBuilder.GetUpdateCommand()
daUpdate.Update(dsUpdate.Tables(0))

myconnection.Close()

All now working well.

Many thanks

Peter

Nov 21 '05 #6

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

Similar topics

2
by: Mark | last post by:
Hi, I have a datalist that I use to display and edit records to a user. Datalist shown below; visual basic code:-----------------------------------------------------------------------...
1
by: niki | last post by:
Hello. I have a problem with custom columns inside the datagrid. I've set up a datagrid that populates from a database; I can edit the datagrid values and update the db, so that's ok. (btw, it's...
3
by: Jim in Arizona | last post by:
I'm doing my best to learn ASPNET from a book devoted to ASPNET 1.0. So far, I haven't run into any problems, until now. This is a simple page that should just show the sql strings created by the...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
5
by: wandii | last post by:
Hi, I am trying to update the customer table by using the updatecommd, please see below, however, when it runs it does not fire the update statement. I ran the sql profiler and the only...
1
by: Rich | last post by:
Hello, I can update a dataset from my client app using a dataAdapter.Updatecommand when I add parameter values outside of the param declaration. But If I add the param values inline with the...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
1
by: SAL | last post by:
Hello, I created a datagrid where I set the Events to there associated functions (i.e. Grid1_UpdateCommand, etc.). All these Events I have established work as they are suppose to except for my...
0
by: stuart_dent | last post by:
I have a SQL Server table with in Indetity column (value auto generated). I have tried to write my own updatecommand code. I can't get it to work. An error says that says Sku and rid are...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.