nomar2
asked on
Inserting into a Database from a Dataset - Formula Help VB.Net Easy Question
I have an easy one.
I have a web method set-up that accepts a dataset from client.
Dim myDA1 As SqlDataAdapter = New SqlDataAdapter
myDA1.InsertCommand = New SqlCommand("Insert into Rec_Orders (order_Number, qty, cost, value) Values (@order_Number, @qty, @cost, (@cost * @qty))", myConn)
myDA1.InsertCommand.Parame ters.Add(" @order_Num ber", SqlDbType.Int, 4, "order_Number")
myDA1.InsertCommand.Parame ters.Add(" @qty", SqlDbType.Int, 9, "qty")
myDA1.InsertCommand.Parame ters.Add(" @cost", SqlDbType.Int, 9, "cost")
'right here ...I am talking about
myDA1.InsertCommand.Parame ters.Add(" (@cost * @qty)", SqlDbType.Int, 9, "value")
Dim param As SqlParameter = myDA1.InsertCommand.Parame ters.Add(" @Identity" , SqlDbType.Int, 0, "id")
param.Direction = ParameterDirection.Output
myDA1.Update(ds1, "rec_Types")
My question is I am inserting into a table that has 4 fields.
OrderNumber
qty
cost
Value
The Value field is a field that is populated by qty multipled by cost...ie (@qty * @cost)
Do I have this done right in my Insert Statement and also have I got it right in the section where I declare my parameters.
Any insight or help would be great.
I have a web method set-up that accepts a dataset from client.
Dim myDA1 As SqlDataAdapter = New SqlDataAdapter
myDA1.InsertCommand = New SqlCommand("Insert into Rec_Orders (order_Number, qty, cost, value) Values (@order_Number, @qty, @cost, (@cost * @qty))", myConn)
myDA1.InsertCommand.Parame
myDA1.InsertCommand.Parame
myDA1.InsertCommand.Parame
'right here ...I am talking about
myDA1.InsertCommand.Parame
Dim param As SqlParameter = myDA1.InsertCommand.Parame
param.Direction = ParameterDirection.Output
myDA1.Update(ds1, "rec_Types")
My question is I am inserting into a table that has 4 fields.
OrderNumber
qty
cost
Value
The Value field is a field that is populated by qty multipled by cost...ie (@qty * @cost)
Do I have this done right in my Insert Statement and also have I got it right in the section where I declare my parameters.
Any insight or help would be great.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
myDA1.InsertCommand = New SqlCommand("Insert into Rec_Orders (order_Number, qty, cost, value) Values (@order_Number, @qty, @cost, (@cost * @qty))", myConn)
myDA1.InsertCommand.Parame ters.Add(" (@cost * @qty)", SqlDbType.Int, 9, "value")
Is the above the right way to handle...
1. the formula in the insert statement
2. setting the parameter for the variable that will fill the VALUE field
myDA1.InsertCommand.Parame
Is the above the right way to handle...
1. the formula in the insert statement
2. setting the parameter for the variable that will fill the VALUE field
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent...so I just need this
myDA1.InsertCommand = New SqlCommand("Insert into Rec_Orders (order_Number, qty, cost, value) Values (@order_Number, @qty, @cost, (@cost * @qty))", myConn)
myDA1.InsertCommand.Parame ters.Add(" @order_Num ber", SqlDbType.Int, 4, "order_Number")
myDA1.InsertCommand.Parame ters.Add(" @qty", SqlDbType.Int, 9, "qty")
myDA1.InsertCommand.Parame ters.Add(" @cost", SqlDbType.Int, 9, "cost")
...rest of the code
Thanks for the quick turnaround
myDA1.InsertCommand = New SqlCommand("Insert into Rec_Orders (order_Number, qty, cost, value) Values (@order_Number, @qty, @cost, (@cost * @qty))", myConn)
myDA1.InsertCommand.Parame
myDA1.InsertCommand.Parame
myDA1.InsertCommand.Parame
...rest of the code
Thanks for the quick turnaround
Values (@order_Number, ,
hope this is your problem!