andycrellin
asked on
vb.net parameterized query fails looking for existing parameter
I get the following error on the following code at (cmd.executenonquery) and can't see the problem:
Parameterized Query '(@TS datetime,@M varchar(300),@H varchar(300),@A varchar(300),@M' expects parameter @TS, which was not supplied.
The code is in the code snippet bit.
I have checked the cmd object at the point of failure and it has 10 parameters, one of which is indeed the one shown in the error.
Any help appreciated - even if its just telling me what I have obviously missed!!
Andy.
Parameterized Query '(@TS datetime,@M varchar(300),@H varchar(300),@A varchar(300),@M' expects parameter @TS, which was not supplied.
The code is in the code snippet bit.
I have checked the cmd object at the point of failure and it has 10 parameters, one of which is indeed the one shown in the error.
Any help appreciated - even if its just telling me what I have obviously missed!!
Andy.
' send data to database
Dim conString As String = "Server=xxxxx\yyyyyyyy;Database=zzzzzzz;Trusted_Connection=True;"
Dim con As New SqlConnection(conString)
Dim cmdCommand As String
con.Open()
With dsSpreads.Tables("ssssss")
cmdCommand = "INSERT INTO sssTable (ts, m, ht, at," & _
" mk, s, b, n, c, t)" & _
" VALUES (@TS, @M, @H, @A, @MK, @S, @B, @N, @C, @T )"
For i As Integer = 0 To .Rows.Count - 1
Dim cmd As New SqlCommand(cmdCommand, con)
cmd.Parameters.Add("@TS", SqlDbType.DateTime, 50, .Rows(i).Item("ts"))
cmd.Parameters.Add("@M", SqlDbType.VarChar, 300, .Rows(i).Item("m"))
cmd.Parameters.Add("@H", SqlDbType.VarChar, 300, .Rows(i).Item("h"))
cmd.Parameters.Add("@A", SqlDbType.VarChar, 300, .Rows(i).Item("a"))
cmd.Parameters.Add("@MK", SqlDbType.VarChar, 300, .Rows(i).Item("mk"))
cmd.Parameters.Add("@S", SqlDbType.Decimal, 18, .Rows(i).Item("s"))
cmd.Parameters.Add("@B", SqlDbType.Decimal, 18, .Rows(i).Item("b"))
cmd.Parameters.Add("@N", SqlDbType.VarChar, 1000, .Rows(i).Item("n"))
cmd.Parameters.Add("@C", SqlDbType.VarChar, 100, .Rows(i).Item("c"))
cmd.Parameters.Add("@T", SqlDbType.VarChar, 100, .Rows(i).Item("t"))
cmd.ExecuteNonQuery()
cmd = Nothing
Next
End With
con.Close()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER