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

Problem with SQLDataAdapter and Update

Ok...I'm new to .NET. I have been programming in C,and VB since 1983.
I am trying to get a simple ADO.NET and Vb.NET example to run using
SQL Server and Northwind database.

I have a form with fields for Employee ID, Last Name, First Name, TitleOfCourtesy,
and BirthDate. I have bound these to a dataset and DataAdapter.

'Create the SQL Connection, DataAdapter, and DataSet
mySQLConnection = New SqlConnection("server=myServer;database=Northwind; Uid=me;Pwd=password;")
mySLQDataAdapter = New SqlDataAdapter("select * from Employees where EmployeeID=1", mySQLConnection)
mySLQDataAdapter.TableMappings.Add("Employees", "Employees")
myDataSet = New DataSet

sqlCBuilder = New SqlCommandBuilder(mySLQDataAdapter)
mySLQDataAdapter.DeleteCommand = sqlCBuilder.GetDeleteCommand()
mySLQDataAdapter.InsertCommand = sqlCBuilder.GetInsertCommand()
mySLQDataAdapter.UpdateCommand = sqlCBuilder.GetUpdateCommand()

mySLQDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

mySLQDataAdapter.Fill(myDataSet, "Employees")

'Bind Data to Controls
txtEmployeeID.DataBindings.Add(New Binding("Text", myDataSet, "Employees.EmployeeID"))
txtLastName.DataBindings.Add(New Binding("Text", myDataSet, "Employees.LastName"))
txtFirstName.DataBindings.Add(New Binding("Text", myDataSet, "Employees.FirstName"))
dtDOB.DataBindings.Add(New Binding("Value", myDataSet, "Employees.BirthDate"))
txtTitle.DataBindings.Add(New Binding("Text", myDataSet, "Employees.TitleOfCourtesy"))

This does everything it should, I believe. My fields are filled with the
correct record. The problem comes when I try to update the data. I make changes
to the LastName field and press my Save button. The button executes the following
code:

mySLQDataAdapter.Update(myDataSet, "Employees")

No exceptions are thrown. However, the data is never updated. I checked the value
of the dataset field in the intermediate window
?me.myDataSet.Tables("Employees").Rows(0).Item("La stName")
"Davolios" {String}
String: "Davolios"

(I added an s to the last name.)

I know I am overlooking something obvious, but I have looked at it toooooooo long.

Please help!
Thanks
Ranny

User submitted from AEWNET (http://www.aewnet.com/)
Nov 21 '05 #1
3 1336
Ranny,
\\\
Bindingcontext(myDataset.tables("Employees").Endcu rrentedit
///
before
mySLQDataAdapter.Update(myDataSet, "Employees")

I hope this helps,

Cor
Nov 21 '05 #2
Cor
Thanks for the response. I guess I am kinda of slow. When I add that line
just in front of the update statement I get "'EndcurrentEdit' is not a member of
'System.Data.DataTable'".
What am I missing??????
Ranny
Ok...I'm new to .NET. I have been programming in C,and VB since 1983.
I am trying to get a simple ADO.NET and Vb.NET example to run using
SQL Server and Northwind database.

I have a form with fields for Employee ID, Last Name, First Name, TitleOfCourtesy,
and BirthDate. I have bound these to a dataset and DataAdapter.

'Create the SQL Connection, DataAdapter, and DataSet
mySQLConnection = New SqlConnection("server=myServer;database=Northwind; Uid=me;Pwd=password;")
mySLQDataAdapter = New SqlDataAdapter("select * from Employees where EmployeeID=1", mySQLConnection)
mySLQDataAdapter.TableMappings.Add("Employees", "Employees")
myDataSet = New DataSet

sqlCBuilder = New SqlCommandBuilder(mySLQDataAdapter)
mySLQDataAdapter.DeleteCommand = sqlCBuilder.GetDeleteCommand()
mySLQDataAdapter.InsertCommand = sqlCBuilder.GetInsertCommand()
mySLQDataAdapter.UpdateCommand = sqlCBuilder.GetUpdateCommand()

mySLQDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

mySLQDataAdapter.Fill(myDataSet, "Employees")

'Bind Data to Controls
txtEmployeeID.DataBindings.Add(New Binding("Text", myDataSet, "Employees.EmployeeID"))
txtLastName.DataBindings.Add(New Binding("Text", myDataSet, "Employees.LastName"))
txtFirstName.DataBindings.Add(New Binding("Text", myDataSet, "Employees.FirstName"))
dtDOB.DataBindings.Add(New Binding("Value", myDataSet, "Employees.BirthDate"))
txtTitle.DataBindings.Add(New Binding("Text", myDataSet, "Employees.TitleOfCourtesy"))

This does everything it should, I believe. My fields are filled with the
correct record. The problem comes when I try to update the data. I make changes
to the LastName field and press my Save button. The button executes the following
code:

mySLQDataAdapter.Update(myDataSet, "Employees")

No exceptions are thrown. However, the data is never updated. I checked the value
of the dataset field in the intermediate window
?me.myDataSet.Tables("Employees").Rows(0).Item("La stName")
"Davolios" {String}
String: "Davolios"

(I added an s to the last name.)

I know I am overlooking something obvious, but I have looked at it toooooooo long.

Please help!
Thanks
Ranny

User submitted from AEWNET (http://www.aewnet.com/)


User submitted from AEWNET (http://www.aewnet.com/)
Nov 21 '05 #3
Doh

\\\
Bindingcontext(myDataset.tables("Employees").Endcu rrentedit
///


Bindingcontext(myDataset.tables("Employees")).Endc urrentedit
Nov 21 '05 #4

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

Similar topics

1
by: Steven Blair | last post by:
Hi, Here is a short decsription of my problem. I have written a dll for Database accessing. I have one method which can return a Dataset and another method which takes a Dataset and upates a...
4
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can...
3
by: Steven Blair | last post by:
Hi, I have a problem understanding the SqlDataAdaptor and the DataSet. I have a dll which has various methods for running stored procedures etc. It also has a method which allows the client to...
3
by: W Akthar | last post by:
Hi I am trying to create a windows service which queries SQL Server on timed intervals and depending on the results send appointments to Outlook. The problem lies when I try to create an...
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...
3
by: LP | last post by:
Hello, In the past I used SqlCommandBuilder and SqlDataAdapter .Update method to apply changes in a DataTable back to its table source in SQL Server. It worked fine when DataSet had only 1...
2
by: chris | last post by:
hi, i managed to populate my datagris and add a template colum to update the database. when i click the update button i get an error. is there something wrong with my code. ...
4
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this...
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...
12
by: Simon | last post by:
Hi all, I'm having a baffling problem with a windows service that I'm working on. Basically, I am using a typed dataset to insert a large number of rows into an SQL Server 2005 database. But...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.