-
Feb 27th, 2018, 11:04 AM
#1
Thread Starter
New Member
[RESOLVED] Fatal error encountered parameter '@sid' must be defined
Hello,
I am facing the error in image pls help me to resolve the issue. following is the code in which I am facing the problem
Code:
ConnDB()
sqL = "INSERT INTO supplier_payments (sup_id,billno,paid_amount,cdate,balance,description) VALUES (@sid,@billno,@payamnt,@date,@balance,@desc)"
cmd.Parameters.AddWithValue("@sid", supDGV.SelectedCells(0).Value)
cmd.Parameters.AddWithValue("@billno", txtbillno.Text)
cmd.Parameters.AddWithValue("@payamnt", txtPayAmount.Text)
cmd.Parameters.AddWithValue("@date", Date.Now())
cmd.Parameters.AddWithValue("@balance", balance)
cmd.Parameters.AddWithValue("@desc", "Balance Paid")
cmd = New MySqlCommand(sqL, conn)
Dim count As Integer = cmd.ExecuteNonQuery()
Thanks in advance.
-
Feb 27th, 2018, 11:10 AM
#2
Re: Fatal error encountered parameter '@sid' must be defined
According to this link http://www.eiben.weite-welt.com/2011...ries-in-mysql/
@ is not a valid character for a placeholder in MySQL. Instead ? should be used.
so try
Code:
sqL = "INSERT INTO supplier_payments (sup_id,billno,paid_amount,cdate,balance,description) VALUES (?sid,?billno,?payamnt,?date,?balance,?desc)"
cmd.Parameters.AddWithValue("?sid", supDGV.SelectedCells(0).Value)
cmd.Parameters.AddWithValue("?billno", txtbillno.Text)
cmd.Parameters.AddWithValue("?payamnt", txtPayAmount.Text)
cmd.Parameters.AddWithValue("?date", Date.Now())
cmd.Parameters.AddWithValue(""balance", balance)
cmd.Parameters.AddWithValue("?desc", "Balance Paid")
cmd = New MySqlCommand(sqL, conn)
Dim count As Integer = cmd.ExecuteNonQuery()
-tg
-
Feb 27th, 2018, 11:17 AM
#3
Thread Starter
New Member
Re: Fatal error encountered parameter '@sid' must be defined
Replacing @ with ? didn't resolve the problem, giving the same error.
-
Feb 27th, 2018, 11:26 AM
#4
Re: Fatal error encountered parameter '@sid' must be defined
Can't be quite the same error. Is it now saying '?sid' must be defined, or is it still saying what it was?
My usual boring signature: Nothing
-
Feb 27th, 2018, 11:30 AM
#5
Thread Starter
New Member
Re: Fatal error encountered parameter '@sid' must be defined
Yes its now saying ?sid must be defined
-
Feb 27th, 2018, 11:30 AM
#6
Re: Fatal error encountered parameter '@sid' must be defined
hmmm.... okay....
So I went back to the documentation - https://dev.mysql.com/doc/connector-...preparing.html
Your setup looks OK.
OH.... wait... no it doesn't.... you add parameters to the command object first... and then create a new instance of the command object (and in the process obliterate you parameters you just added)
You just need to move one line, the one where you create a new command object to be before the paramers.addwithvalues:
Code:
sqL = "INSERT INTO supplier_payments (sup_id,billno,paid_amount,cdate,balance,description) VALUES (@sid,@billno,@payamnt,@date,@balance,@desc)"
cmd = New MySqlCommand(sqL, conn) ' This should be up here, so the parameters are added to THIS instance of the command
cmd.Parameters.AddWithValue("@sid", supDGV.SelectedCells(0).Value)
cmd.Parameters.AddWithValue("@billno", txtbillno.Text)
cmd.Parameters.AddWithValue("@payamnt", txtPayAmount.Text)
cmd.Parameters.AddWithValue("@date", Date.Now())
cmd.Parameters.AddWithValue("@balance", balance)
cmd.Parameters.AddWithValue("@desc", "Balance Paid")
Dim count As Integer = cmd.ExecuteNonQuery()
-tg
-
Feb 27th, 2018, 11:37 AM
#7
Thread Starter
New Member
Re: Fatal error encountered parameter '@sid' must be defined
-
Feb 27th, 2018, 11:38 AM
#8
Re: [RESOLVED] Fatal error encountered parameter '@sid' must be defined
My usual boring signature: Nothing
-
Feb 27th, 2018, 11:51 AM
#9
Re: [RESOLVED] Fatal error encountered parameter '@sid' must be defined
The only reason I caught it is because I started to look for the definition of cmd ... I know I've had issues before when I didn't set the commandtype correctly, and so I wanted to verify that... and that's when I noticed the creation of the command object was "missing"... wait, no not missing, just in the wrong spot. It's one of those little things, easily missed.
-tg
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|