I am filling a table from an SP with the following columns:-
SELECT Sotrn.SotrnId, InvoiceName + ' (' + crctl.CrcAbrev + ')' AS Customer
, Sotrn.No_Units as Units, Sotrn.Unit_Price AS Price, Slrep.RepName, Hauliers.Haul_Desc AS Haulier, [Depot Name] as [Dispatch_From],
sohed.KeyDate as Dispatch, Potrn.PotrnId, Potrn.Ord_Units
FROM Sotrn INNER JOIN Etc Etc
This works fine.
I then created an Sqlcommand to update this as follows:-
dim cmdUpdateOrders as New SqlCommand
Try
cmdUpdateOrders.Parameters.AddRange(New SqlParameter() _
{New SqlParameter("@Units", SqlDbType.SmallMoney), _
New SqlParameter("@Price", SqlDbType.SmallMoney), _
New SqlParameter("@SotrnId", SqlDbType.Int), _
New SqlParameter("@PotrnId", SqlDbType.Int)})
cmdUpdateOrders.CommandType = CommandType.StoredProcedure
cmdUpdateOrders.Connection = CON
cmdUpdateOrders.CommandText = "CtsWtUpdateSOrds"
Catch ex As Exception
MsgBox("Error " & ex.Message & " in Setup_StockOrder_Query - CmdUpdateOrders ")
End Try
The SP for the update is as follows:-
ALTER PROCEDURE [dbo].[CtsWtUpdateSOrds] @Units SmallMoney, @Price SmallMoney, @SotrnId Integer, @PotrnId Integer
AS
UPDATE Sotrn SET No_Units = @Units, Unit_Price = @Price WHERE SotrnId = @Sotrnid
UPDATE Potrn SET Ord_Units = @Units WHERE PotrnId = @Potrnid
but when I try the following code:-
Try
AD.UpdateCommand = cmdUpdateOrders
AD.Update(DS, "StockOrderAlloc")
Catch ex As Exception
MsgBox("Error " & ex.Message & " in cmdUpdateChanges_Click")
End Try
I get :-
Error Procedure or Function CtswtUpdateSOrds expects parameter '@Units', which was not supplied.
I think I am nearly there.
Any ideas anyone?
For Example
Dim connectionstring as string
connectionstring = "server=MyServer;" & _
"database=MyDatabaseDB;uid
Dim sqlparams(3) as SqlClient.SqlParameter
sqlparams(0) = new SqlClient.SqlParameter("@i
sqlparams(0).Value = Ctype(ddlInputOne.Selected
sqlparams(1) = new SqlClient.SqlParameter("@i
sqlparams(1).Value = Ctype(ddlInputtwo.Selected
sqlparams(2) = new SqlClient.SqlParameter("@i
sqlparams(2).Value = Ctype(ddlInputthree.Select
refer
http://www.codeproject.com/Articles/8180/Using-SQLParameters-with-VB-NET-C