Results 1 to 3 of 3

Thread: Help Me - Scalar Variable

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    67

    Help Me - Scalar Variable

    I have this program but when i debug i, dont know what the error is.

    What im trying to do here is to pass a data from a Form(MainMenu) to a class(tableClass) to be process. From the MainMenu i assign Cust_table with 1, thats the integer shall be pass to tableClass.

    Code:
    Dim Cust_table As New TableClass
            Cust_table.Table_No = 1



    Upon receiving data from MainMenu form. If u can see, the blue code part
    is working fine. But when it comes to If, else. It have this error


    Must declare the scalar variable "@Cust_table".



    TableClass code
    Code:
    
    
    Get
                Return Cust_table
            End Get
            Set(ByVal value)
                Cust_table = value
    
    Dim Conn As New SqlConnection("Data Source=ANNAS;Initial Catalog=RMS01;Integrated Security=True")
    
    Dim command As New SqlCommand("SELECT Counter FROM CounterMeja WHERE Meja = @Cust_table", Conn)
    
                Conn.Open()
                command.Parameters.AddWithValue("Cust_table", Cust_table)
                command.ExecuteScalar()
    
    
                If Counter = 0 Then
    
                    Dim command2 As New SqlCommand("Update CounterMeja Set 
                    Counter = 1 Where Meja = @Cust_table", Conn)
                    Command.Parameters.AddWithValue("Cust_table", Cust_table)
                    command2.ExecuteNonQuery()
                    OrderForm.Show()
                Else
                    Dim Result As String
                    Result = ("Sorry this table has already been occupied")
                End If
    
                Conn.Close()
    My second question is, why can't i use CustTable in first part not the second part. Eventh thought it already been assign the parameter pass right.

    thank U

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: Help Me - Scalar Variable

    change
    vb Code:
    1. commad.Parameter.addWithValue("Cust_Table", Cust_Table)
    to
    vb Code:
    1. commad.Parameter.addWithValue("@Cust_Table", Cust_Table)

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Help Me - Scalar Variable

    They are two different commands.... the first one you add the parameter to... which is good... but on the second one, you've used Command again instead of Command2.... so it's never adding the parameter to your second command, it just simply added it again to the second one.

    -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??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width