What is the equivalent of a RecordSet

eldercise

New Member
I have just begun to understand using DataSets for output, but I am still really unsure as to how to update records. I used to do something like:<BR>sql = "SELECT * FROM table1 WHERE ID = something;"<BR>RS.open<BR>RS("field1") = info1<BR>RS("field2") = info2<BR>RS.Update<BR>RS.close<BR><BR>But I haven't seen much of that yet. IBuySpy uses Store Procedures exclusively and I haven't seen much else.<BR><BR>ThanksThere is no real equivalent to a recordset.<BR><BR>There are some very important problems with recordsets, they need to be connected to the database and they hog resources in both the server and client. They work pretty well with 1 user but they kill upgreadeability.<BR><BR>Microsof has gone all out to redesign this model with a disconnected model. You now connect to the database, get all of your data into a a DataSet and close the connection. You can now use the DataSet to access and modify the data till you are happy with it, then update the dataset which will connect to the database and update itself. It is actually an amazing model with very good posibilities.<BR><BR>To your question lets write some code (in this case copy paste from the howtos that come with the framework)<BR>//Setting up variables<BR>String InsertCmdString;<BR>InsertCmdString = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";<BR>SqlConnection mySqlConnection = new SqlConnection("server=(local)\VSdotNET;uid=QSUser;pwd=QSPassword; database=northwind");<BR><BR>//ok to do the work<BR>mySqlConnection.Open();<BR>SqlCommand mySqlCommand = new SqlCommand(InsertCmdString, myConnection);<BR>mySqlCommand.ExecuteNonQuery(); //this actually goes to the database<BR>myConnection.Close() //don't forget to close this<BR><BR>But wait! after all that boring talk about DataSets in the begining I give you an example that has nothing to do with them? well yes. The Connection and Command objects are central to understanding ADO.NET. You can still do stuff the old way. Lets take a look at how this would work with a DataSet:<BR><BR>String SelectCmdString = "select * from todo";<BR>mySqlConnection.Open();<BR>SqlCommand mySqlCommand = new SqlCommand(SelectCmdString , mySqlConnection);<BR>//Heres Johnny!<BR>DataSet myDataSet = new DataSet();<BR>SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySqlCommand);<BR>mySqlDataAdapter.Fill(myDataSet); <BR>mySqlConnection.Close();<BR><BR>And now you have a disconected DataSet that you can play with. You can look at the data, modify it convert it to/from xml etc. <BR>when you are done DataSet.AcceptChanges() automagically connects itself back up to the database, updates itself and closes the connection. Of course there is much more you can do with DataSets, read up!<BR><BR>happy programming<BR>asb
 
Back
Top