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

Problem with using UpdateCommand property

The following procedure does not Update the record(s).
'------------------------------------------------------------------
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim dadapter As OleDbDataAdapter = New OleDbDataAdapter
Dim CmdBuilder As OleDbCommandBuilder = New
OleDbCommandBuilder(dadapter)
Dim strSelect = "SELECT CustomerID, CompanyName FROM Customers"
Dim cmdSelect As OleDbCommand = New OleDbCommand(strSelect,
Conxn)

Dim DS As DataSet = New DataSet
dadapter.SelectCommand = cmdSelect
dadapter.Fill(DS, "Customers")

Dim strUpdate = "UPDATE " & strCustomers & " " & _
"SET CustomerID = 'COMID', " & _
"CompanyName = 'Cactus Comidas'" & _
"WHERE CustomerID = 'CACTU'"

Dim cmdUpdate As OleDbCommand = New OleDbCommand(strUpdate,
Conxn)
dadapter.UpdateCommand = cmdUpdate

Try
Dim NumRows As Long = dadapter.Update(DS, "Customers")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
'---------------------------------------------------
For academic purpose, I need a solution based on the Update method of
the DataAdapter (Not ExecuteNonQuery of the

Command object). Please suggest a solution.

Nov 23 '05 #1
1 1043
Hi,

Add least do you have to set that commandbuilder, if it has a select
statement and a connection. I woulld not know what it otherwise can build as
commands.

I gues that is your problem

And than remove that hand build update, for that your string is not
sufficient. You miss the information from the select to match to the new
data.

You can drag for that a dataadapber (version 2003) to a new component that
you have added and look what code is generated.

However it is that or the commandbuilder.

I hope this helps,

Cor

<zo****@yahoo.com> schreef in bericht
news:11**********************@g43g2000cwa.googlegr oups.com...
The following procedure does not Update the record(s).
'------------------------------------------------------------------
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim dadapter As OleDbDataAdapter = New OleDbDataAdapter
Dim CmdBuilder As OleDbCommandBuilder = New
OleDbCommandBuilder(dadapter)
Dim strSelect = "SELECT CustomerID, CompanyName FROM Customers"
Dim cmdSelect As OleDbCommand = New OleDbCommand(strSelect,
Conxn)

Dim DS As DataSet = New DataSet
dadapter.SelectCommand = cmdSelect
dadapter.Fill(DS, "Customers")

Dim strUpdate = "UPDATE " & strCustomers & " " & _
"SET CustomerID = 'COMID', " & _
"CompanyName = 'Cactus Comidas'" & _
"WHERE CustomerID = 'CACTU'"

Dim cmdUpdate As OleDbCommand = New OleDbCommand(strUpdate,
Conxn)
dadapter.UpdateCommand = cmdUpdate

Try
Dim NumRows As Long = dadapter.Update(DS, "Customers")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
'---------------------------------------------------
For academic purpose, I need a solution based on the Update method of
the DataAdapter (Not ExecuteNonQuery of the

Command object). Please suggest a solution.

Nov 23 '05 #2

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

Similar topics

3
by: Andrew Dodgshun | last post by:
I have 2 grids - one shows a list of table names in a database and when you click on a table name the other grid dynamically populates the grid with the table contents. My problem is that I cannot...
7
by: Zachary Hilbun | last post by:
The below is some test code to help me learn how to update a dataset. It is supposed to read the value of UserCounter and write it back. The UserCounter is being read correctly as 0, is 1 when...
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();
0
by: clickon | last post by:
I want to use an INSERT Query as the value for the UpdateCommand property of an SQL datasource, anyone know if this will actually work ? The reason i want to do it is bacause i am taking values...
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...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
2
by: Scotty | last post by:
I get stuck to write an update, insert and delete command, i am looking for some help to start Whats the best way to update 2 tables toe the database (Access) below my code used to load my...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.