Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to ASP.NET

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
When I programmed in ASP before I would do my insert into a database like this. How would I do the same thing in .net? can I do it the same way?

dbrs2.open ("Select * From Timesheet where loginID = '" & request.form("employee1")& "' and month = '" & request.form("month1")& "'" ), dbconn, 2, 3

dbrs2.addnew
dbrs2("date")=request("date1")
dbrs2("hour")=request("hour1")
dbrs2("code")=request("code1")
dbrs2("twentymiles")=request("twentymiles")
dbrs2("fiftymiles")=request("fiftymiles")
dbrs2("stairclimbers")=request("stairclimbers")
dbrs2.update
dbrs2.movenext
 
There is a big difference between ADO and ADO.NET, it's more an improvement than a difference. While with ASP and ADO we where using recordsets (connected objects), with ASP.NET and ADO.NET we are using DataSets (disconnected objects), therefore when you are updating a DataSet, you are not really updating the Database at all! What to do now? Use the DataAdapter. The DataAdapter is the object used to manage the connection between your DataSet and the DataBase (using the Connection object as well).
Therefore you want to create a DataAdapter object, pass the connection and the SELECT statement and let the wizard create your insert, update and delete statements for you.
After that all you have to do is:

// da is your DataAdapter, ds is your DataSet

da.Update(ds,"MyTable"); //in c#

da.Update(ds,"MyTable") 'in VB.NET

This method will be called after you added a new row, or after you updated some fields in the dataset, or after deleting a record.

To fill a DataSet using the DataAdpater all you need to do is:

da.Fill(ds,"MyTable); //in c#

da.Fill(ds,"MyTAble) 'in VB.NET


hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top