|
-
Mar 14th, 2008, 06:35 PM
#1
Thread Starter
Lively Member
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
-
Mar 14th, 2008, 07:54 PM
#2
Fanatic Member
Re: Help Me - Scalar Variable
change
vb Code:
commad.Parameter.addWithValue("Cust_Table", Cust_Table)
to
vb Code:
commad.Parameter.addWithValue("@Cust_Table", Cust_Table)
-
Mar 14th, 2008, 08:49 PM
#3
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
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
|