Greetings,
I am looking at the following code snippit in "SAM's Learn ASP.NET in 21 Days"
The book then goes on to say:
Unless there is something that I'm missing or not understanding, this seems like double duty to me. What is the point of adding a new row to a DataSet, only to have it do nothing for you when you call the Update method to update your underlying database without having to manually write the SQL with the values you've already added to the dataset to insert the data?
I know you can use the OleDbCommandBuilder() object to generate the SQL automatically - but this still seems like double duty.
~Melagan
______
"It's never too late to become what you might have been.
I am looking at the following code snippit in "SAM's Learn ASP.NET in 21 Days"
Code:
Dim Conn as New OleDbConnection( _
"Provider=Microsoft.Jet.Oledb.4.0;" & _
"Data Source="X:\mydb.mdb")
Dim ds as New DataSet("myDataSet")
Dim objCmd as New OleDbDataAdapter("SELECT * FROM " & _
"tblUsers WHERE UserID < 10", Conn)
objCmd.Fill(ds, "tblUsers")
Dim dr as DataRow = ds.Tables("tblUsers").NewRow()
dr(0) = "Greg"
dr(1) = "Smith"
dr(2) = "434 Maple Apt B"
dr(3) = "Minneapolis"
dr(4) = "MN"
dr(5) = "12588"
dr(6) = "5189876259"
ds.Tables("tblUsers").Rows.Add(dr)
objCmd.InsertCommand = new OleDbCommand
objCmd.InsertCommand.Text = "Insert INTO " & _
"tblUsers (FirstName, LastName, Address, City, " & _
"State, Zip, Phone) VALUES ('Greg', 'Smith', " & _
"'434 Maple Apt B', 'Minneapolis', 'MN', '12588', " & _
"'5189876259'"
objCmd.InsertCommand.Connection = Conn
The book then goes on to say:
Note that these commands don't really alter any data. They merely provide commands to instruct ADO.NET how you want to push the data that you've already changed. For example, if you hadn't made any changes on lines [data row above], the command methods would do nothing, regardless of the SQL statements you specified.
Unless there is something that I'm missing or not understanding, this seems like double duty to me. What is the point of adding a new row to a DataSet, only to have it do nothing for you when you call the Update method to update your underlying database without having to manually write the SQL with the values you've already added to the dataset to insert the data?
I know you can use the OleDbCommandBuilder() object to generate the SQL automatically - but this still seems like double duty.
~Melagan
______
"It's never too late to become what you might have been.