Problem with SQLDataAdapter and Update

  • Thread starter Thread starter Ranny
  • Start date Start date
R

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("LastName")
"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/)
 
Ranny,


\\\
Bindingcontext(myDataset.tables("Employees").Endcurrentedit
///
before
mySLQDataAdapter.Update(myDataSet, "Employees")
I hope this helps,

Cor
 
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("LastName")
"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/)
 
Back
Top