I have a question about programming the VB ADO.NET database tools.
I'm doing a program that talks to an SQL Server database using ADO.Net. I've read the MS ADO.Net book through and am a bit confused in Chapter 10 where it talks about binding SQLCommand object parameters to columns in a DataTable, within a DataSet vs binding those parameters to controls on the form.
No, I'm not using a DataForm Wizard.
I'm kinda confused about how the DataAdapter objects Update() method actually works. When I call objDataAdapter.Update(objDataSet) what I think is happening is that the DataAdapter uses the SQLCommand associated with the Update method and the columns in the DataSet object to form an SQL command which is sent to the DB which does the table updating. I think the values it uses are the values in the DataSet and if you tell it so by using the SQLParameter's SourceVersion property you can force it to use original values (in the DataSet) instead of current values (in the DataSet).
I'm using a set of controls bound to the DataSet so again I think that the current values in the DataSet are the values in the bound controls and the "original" values are the ones that came up from the database after the last time data was loaded from the database.
Here's my original code that (I think) binds SQL Command parameters to controls on the form.
objUpdateExpenseCommand = New SqlCommand("UPDATE tblExpenses SET ExpenseReportNumber = @ExpenseReportNumber, " & _
"ExpenseDate = @ExpenseDate, " & _
"PrePaid = @PrePaid, " & _
"Vendor = @Vendor, " & _
"LocationVisited = @LocationVisited, " & _
"MilesTraveled = @MilesTraveled, " & _
"Class = @Class, " & _
"Days = @Days, " & _
"PersonsEntertained = @PersonsEntertained, " & _
"Company = @Company, " & _
"Purpose = @Purpose, " & _
"Place = @Place, " & _
"Other = @Other, " & _
"CategoryNumber = @CategoryNumber, " & _
"DirectBill = @DirectBill, " & _
"Cost = convert(money,@Cost) " & _
"WHERE ExpenseNumber = @ExpenseNumber")
objUpdateExpenseCommand.Connection = objConnection
In Chapter 10 of my book, it talks about a different Add() method syntax that looks like this:
.Add("@ExpenseNumber", OleDBType.Integer, 0, "ExpenseNumber")
It seems to me that this does basically the same thing... just differently. I'm confused about how the parameter is connected to the data columns. I seems you just need to have a table with the same named column when you use the alternate syntax.
Does this make much of a difference? If I'm bound to the controls and those have the current value how is this different from being bound to the DataSet or DataTable and using the current value there?