By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,065 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,065 IT Pros & Developers. It's quick & easy.

Problem with SQLDataAdapter and Update

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
Ranny,
\\\
Bindingcontext(myDataset.tables("Employees").Endcu rrentedit
///
before
mySLQDataAdapter.Update(myDataSet, "Employees")

I hope this helps,

Cor
Nov 21 '05 #2

P: n/a
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

P: n/a
Doh

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


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

This discussion thread is closed

Replies have been disabled for this discussion.