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.StoredProcedur e
Dim NewCateringOrderID As SqlParameter
NewCateringOrderID = New SqlParameter("@NewCatering OrderID", SqlDbType.BigInt)
NewCateringOrderID.Directi on = ParameterDirection.Output
cmd.Parameters.Add(NewCate ringOrderI D)
' pass customer info to stored proc
cmd.Parameters.Add("@Event Date", txtEventDate.Text)
cmd.Parameters.Add("@First Name", 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?
cmd = New SqlCommand("Add_NewOrder",
cmd.CommandType = CommandType.StoredProcedur
Dim NewCateringOrderID As SqlParameter
NewCateringOrderID = New SqlParameter("@NewCatering
NewCateringOrderID.Directi
cmd.Parameters.Add(NewCate
' pass customer info to stored proc
cmd.Parameters.Add("@Event
cmd.Parameters.Add("@First
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you use the Data Apdapter's update method you must first endcurrentedit. ie:
Me.BindingContext(DS, "DT").EndCurrentEdit()
Me.BindingContext(DS, "DT").EndCurrentEdit()
data adpater's InsertCommand, DeleteCommand, or UpdateCommand is executed.