when writing to DB error : Must declare the variable '@MID'

hello,

I was wondering if anybody can help me, When trying to write to my table, i am given the exception : Must declare the variable'@MID'

The other functions i have that do much the same thing work fine, so im not sure whats the cause? Im new to programming and any advice would be greatly appreciated.

Thanks a lot!!

Here is the code:

PublicFunction WriteSerialToDB(ByVal serialAsString,ByVal vMIDAsString,ByVal compIDAsString)AsBoolean

Dim connStringAsString ="Data Source=Cayenne;Initial Catalog=""PCOPEN DATA"";Persist Security Info=True;User ID=*********;Password=********"

Dim conInsertAs SqlConnection

Dim strAddAsString

Dim newCmdInsertAs SqlCommand

Dim MIDAsString = vMID

Dim dte2AsString = DateTime.Now

conInsert =New SqlConnection(connString)

strAdd ="INSERT tblOEM_ProductPurchase( ModelID, DateOrdered, SerialNumber, ProductRegistered ) Values ( @ModelID, @DateOrdered, @SerialNumber, @ProductRegistered)"

newCmdInsert =New SqlCommand(strAdd, conInsert)

cmdInsertParameters.AddWithValue("@ModelID", MID)

cmdInsert.Parameters.AddWithValue("@DateOrdered", dte2)

cmdInsert.Parameters.AddWithValues("@SerialNumber", serial)

cmdInsert.Parameters.AddWithValues("@ProductRegistered", "0")

Try

conInsert.Open()

newCmdInsert.ExecuteNonQuery()

conInsert.Close()

Catch exAs Exception

ReturnFalse

EndTry

ReturnTrue

End Function

[4537 byte] By [04-digit0l] at [2007-12-23]
# 1

Lol, never mind....

I think ive been staring at a screen too long today....

cmdInsert.Paramenters should be newCmdInsert

Ok then, time to go home...

04-digit0l at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic Language...