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=North wind;Uid=me;Pwd =password;")
mySLQDataAdapte r = New SqlDataAdapter( "select * from Employees where EmployeeID=1", mySQLConnection )
mySLQDataAdapte r.TableMappings .Add("Employees ", "Employees" )
myDataSet = New DataSet
sqlCBuilder = New SqlCommandBuild er(mySLQDataAda pter)
mySLQDataAdapte r.DeleteCommand = sqlCBuilder.Get DeleteCommand()
mySLQDataAdapte r.InsertCommand = sqlCBuilder.Get InsertCommand()
mySLQDataAdapte r.UpdateCommand = sqlCBuilder.Get UpdateCommand()
mySLQDataAdapte r.MissingSchema Action = MissingSchemaAc tion.AddWithKey
mySLQDataAdapte r.Fill(myDataSe t, "Employees" )
'Bind Data to Controls
txtEmployeeID.D ataBindings.Add (New Binding("Text", myDataSet, "Employees.Empl oyeeID"))
txtLastName.Dat aBindings.Add(N ew Binding("Text", myDataSet, "Employees.Last Name"))
txtFirstName.Da taBindings.Add( New Binding("Text", myDataSet, "Employees.Firs tName"))
dtDOB.DataBindi ngs.Add(New Binding("Value" , myDataSet, "Employees.Birt hDate"))
txtTitle.DataBi ndings.Add(New Binding("Text", myDataSet, "Employees.Titl eOfCourtesy"))
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:
mySLQDataAdapte r.Update(myData Set, "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.T ables("Employee s").Rows(0).Ite m("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/)