Link to home
Start Free TrialLog in
Avatar of dba123
dba123

asked on

How to update data using class

Normally, I insert data like this for my web pages (VB.NET):

        cmd = New SqlCommand("Add_NewOrder", Conn)
        cmd.CommandType = CommandType.StoredProcedure
        Dim NewCateringOrderID As SqlParameter
        NewCateringOrderID = New SqlParameter("@NewCateringOrderID", SqlDbType.BigInt)
        NewCateringOrderID.Direction = ParameterDirection.Output
        cmd.Parameters.Add(NewCateringOrderID)

        ' pass customer info to stored proc
        cmd.Parameters.Add("@EventDate", txtEventDate.Text)
        cmd.Parameters.Add("@FirstName", txtFName.Text)

        cmd.ExecuteNonQuery()

I am taking a test for a job, and I am guessing they don't want m e to do it this way.  Is there a way to shove an insert into a class as a method then somehow use it to do the insert?  How would I pass parameters or create the right parameters though...meaning if I called the method by creating an instance of the class, how would it know which parameters to create if you wanted to reuse the method?

and what about an update method?
Avatar of pradeepsudharsan
pradeepsudharsan

When the Update method is called, changes in the DataSet are copied back to the database and the appropriate
data adpater's InsertCommand, DeleteCommand, or UpdateCommand is executed.
ASKER CERTIFIED SOLUTION
Avatar of pradeepsudharsan
pradeepsudharsan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you use the Data Apdapter's update method you must first endcurrentedit. ie:

 Me.BindingContext(DS, "DT").EndCurrentEdit()