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.
' 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()

Open in new window

andycrellinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CarlVerretCommented:
Hi,

I suggest you to use the : cmd.Parametes.AddWithValue (@name, _value_) function instead.  It worked really fine for me!

Hope this helps!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andycrellinAuthor Commented:
Well whadyaknow! Worked perfectly, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.