dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] Fatal error encountered parameter '@sid' must be defined

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    12

    Resolved [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()
    Name:  error.png
Views: 118
Size:  38.1 KB

    Thanks in advance.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,772

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    12

    Re: Fatal error encountered parameter '@sid' must be defined

    Replacing @ with ? didn't resolve the problem, giving the same error.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,369

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    12

    Re: Fatal error encountered parameter '@sid' must be defined

    Yes its now saying ?sid must be defined

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,772

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    12

    Re: Fatal error encountered parameter '@sid' must be defined

    Thanks alot.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    32,369

    Re: [RESOLVED] Fatal error encountered parameter '@sid' must be defined

    Yep, I missed that.
    My usual boring signature: Nothing

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,772

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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
  •  



Featured


Click Here to Expand Forum to Full Width