473,489 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help updating table

This should be simple but I can't get it to work. I want to update a single
row of data in a table.

ES.Clear()
Dim strSQL As String = "Select * from Contact where sysid = '" &
g_sysID & "'"
DB = New SqlClient.SqlDataAdapter(strSQL, CN)
DB.Fill(ES, "Contact")

If ES.Tables("Contact").Rows.Count > 0 Then
txtAddress.Text =
ES.Tables("Contact").Rows(0).Item("con1_02_03")
txtFirst_Name.Text =
ES.Tables("Contact").Rows(0).Item("First_Name")
txtLast_Name.Text =
ES.Tables("Contact").Rows(0).Item("Last_Name")
End If
I hope the above is correct

Now in another routine I want to update

Dim objRow As Data.DataRow
objRow = ES.Tables("Contact").Rows(0)
objRow.BeginEdit()
objRow("First_Name") = "Gary"
objRow("Last_Name") = "Smith"
objRow("con1_02_03") = "New Address"
objRow.EndEdit()
objRow.AcceptChanges()
DB.Update(ES, "Contact")
What on earth am I doing wrong?

Thanks,

Gary
Nov 21 '05 #1
4 1221
Looks like you're calling AcceptChanges on the dataset before the Update to
the database. In your case you only want to call AcceptCahnges on the
dataset if the update succeeds. I'd pick up the book "ADO.NET - Core
Reference" by David Sceppa ... it't the ADO.NET bible around here.

HTH,
-B

"Gary Paris" <ya**@somewhereovertherainbow.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This should be simple but I can't get it to work. I want to update a
single row of data in a table.

ES.Clear()
Dim strSQL As String = "Select * from Contact where sysid = '" &
g_sysID & "'"
DB = New SqlClient.SqlDataAdapter(strSQL, CN)
DB.Fill(ES, "Contact")

If ES.Tables("Contact").Rows.Count > 0 Then
txtAddress.Text =
ES.Tables("Contact").Rows(0).Item("con1_02_03")
txtFirst_Name.Text =
ES.Tables("Contact").Rows(0).Item("First_Name")
txtLast_Name.Text =
ES.Tables("Contact").Rows(0).Item("Last_Name")
End If
I hope the above is correct

Now in another routine I want to update

Dim objRow As Data.DataRow
objRow = ES.Tables("Contact").Rows(0)
objRow.BeginEdit()
objRow("First_Name") = "Gary"
objRow("Last_Name") = "Smith"
objRow("con1_02_03") = "New Address"
objRow.EndEdit()
objRow.AcceptChanges()
DB.Update(ES, "Contact")
What on earth am I doing wrong?

Thanks,

Gary

Nov 21 '05 #2
I have the book in question and I am reading Chapter 10, "Submitting Updates
to Your Database". On page 403 there is an example, although not exactly
like mine, it does a delete then an update then an add.

I just wanted to do a simple change. They have an example of submitting the
changes:

da.Update(tbl)

but that doesn't work. What else am I missing? Do I need the BeginEdit or
EndEdit? Do I need the AcceptChanges?

HELP
"Beth Massi [Architect MVP]" <bm****@comcast.net> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
Looks like you're calling AcceptChanges on the dataset before the Update
to the database. In your case you only want to call AcceptCahnges on the
dataset if the update succeeds. I'd pick up the book "ADO.NET - Core
Reference" by David Sceppa ... it't the ADO.NET bible around here.

HTH,
-B

"Gary Paris" <ya**@somewhereovertherainbow.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This should be simple but I can't get it to work. I want to update a
single row of data in a table.

ES.Clear()
Dim strSQL As String = "Select * from Contact where sysid = '" &
g_sysID & "'"
DB = New SqlClient.SqlDataAdapter(strSQL, CN)
DB.Fill(ES, "Contact")

If ES.Tables("Contact").Rows.Count > 0 Then
txtAddress.Text =
ES.Tables("Contact").Rows(0).Item("con1_02_03")
txtFirst_Name.Text =
ES.Tables("Contact").Rows(0).Item("First_Name")
txtLast_Name.Text =
ES.Tables("Contact").Rows(0).Item("Last_Name")
End If
I hope the above is correct

Now in another routine I want to update

Dim objRow As Data.DataRow
objRow = ES.Tables("Contact").Rows(0)
objRow.BeginEdit()
objRow("First_Name") = "Gary"
objRow("Last_Name") = "Smith"
objRow("con1_02_03") = "New Address"
objRow.EndEdit()
objRow.AcceptChanges()
DB.Update(ES, "Contact")
What on earth am I doing wrong?

Thanks,

Gary


Nov 21 '05 #3
Hi Gary,

Don't call AcceptChanges() on the row. Rather, make the changes and call
DB.Update(ES, "Contact").

If the update succeeds, then call AcceptChanges() on your DataSet to
commit the changes permanently.

Regards,
-Adam.

Gary Paris wrote:
This should be simple but I can't get it to work. I want to update a single
row of data in a table.

ES.Clear()
Dim strSQL As String = "Select * from Contact where sysid = '" &
g_sysID & "'"
DB = New SqlClient.SqlDataAdapter(strSQL, CN)
DB.Fill(ES, "Contact")

If ES.Tables("Contact").Rows.Count > 0 Then
txtAddress.Text =
ES.Tables("Contact").Rows(0).Item("con1_02_03")
txtFirst_Name.Text =
ES.Tables("Contact").Rows(0).Item("First_Name")
txtLast_Name.Text =
ES.Tables("Contact").Rows(0).Item("Last_Name")
End If
I hope the above is correct

Now in another routine I want to update

Dim objRow As Data.DataRow
objRow = ES.Tables("Contact").Rows(0)
objRow.BeginEdit()
objRow("First_Name") = "Gary"
objRow("Last_Name") = "Smith"
objRow("con1_02_03") = "New Address"
objRow.EndEdit()
objRow.AcceptChanges()
DB.Update(ES, "Contact")
What on earth am I doing wrong?

Thanks,

Gary

Nov 21 '05 #4
Gary,

Exactly as Beth and Adam told you.

To explain what Acceptchanges does.

When you do a change, than there is set in the dataset for every row a value
(the rowstate) what change has be done. Accoording to that does the
dataadapter an update.

However think on the fact that you are using two datatables. One you use to
update the database and one you use for other things. (By instance when you
use ds.getchanges, than you create a copy of the dataset). Than still you
have to set all those changes back when the update is done in the original
dataset.

For that is the command acceptchanges (as if they are done correct).

So doing that before the update, gives the dataadapter not any information
at all what to update.

I hope that this explains it a little bit.

Cor
Nov 21 '05 #5

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

Similar topics

11
16068
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? ...
9
2912
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
1
1345
by: Jason Shohet | last post by:
We have an app that queries 5 tables into a dataset. Now, lets say 1 of those tables is about to change due to user input on a webpage. Right now, we are manually updating the db with an update...
1
2448
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
11
3042
by: Eych | last post by:
I get a VB error when I try to update a table whose field I change with the following statement: dcUpdate.Dataset.Tables(0).Rows(0)("User Name") = Me.textbox1.Text if I change the field name...
2
2838
by: Alexey.Murin | last post by:
The application we are developing uses MS Access 2003 database (with help of ADO). We have noticed that during massive records updating the size of the mdb file increases dramatically (from 3-4 to...
4
2360
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
0
1333
by: JimN1 | last post by:
Error: Update requires a valid UpdateCommand when passed DataRow collection with modified rows. This is a continuation of my previous table element update question. I am now getting the above...
2
1174
by: ConfusedMay | last post by:
Hi, Could someone help me with updating my table? I'm using access 97. I have a table that have # of tests and test reasons called testing. what I need is if there's any job with test reason...
2
3297
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
7108
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
6967
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...
1
6847
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
5445
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,...
1
4875
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...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
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
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
272
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...

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.