|
|
|
รบกวนด้วยครับ Must declare the scalar variable ขอบคุณครับ |
|
|
|
|
|
|
|
ตามโค๊ดครับ มัน Error อะครับ Must declare the scalar variable "@name"
Code
sql = "Insert into test(Uname,Password) VALUES (@name, @pass)"
cmd = New SqlClient.SqlCommand(sql, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("@name", txt_Username.Text)
cmd.Parameters.AddWithValue("@pass", txt_Password.text)
ลองเปลี่ยนตามนี้ก็ยังไม่ได้ครับ
cmd.Parameters.AddWithValue("name", txt_Username.Text)
cmd.Parameters.AddWithValue("pass", txt_Password.text)
แต่ถ้าผมใช้รับค่าจาก Text โดยตรง Insert ได้ครับไม่ Error
sql = "Insert into test(Uname,Password) VALUES ('" & txt_Username.Text &"', '" & txt_Password.tex &"')"
รบกวนด้วยนะครับผมขอบคุณครับ
Tag : .NET, Ms SQL Server 2008, VS 2013 (.NET 4.x)
|
|
|
|
|
|
Date :
2017-09-06 11:52:04 |
By :
tongchimlang |
View :
2973 |
Reply :
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูวิธีการใช้ Parameters ครับ
Code (VB.NET)
'*** FOR INSERT ***'
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
"VALUES (@sCustomerID,@sName,@sEmail,@sCountryCode,@sBudget,@sUsed)"
objCmd = New System.Data.SqlClient.SqlCommand(strSQL,objConn)
'*** Sample 1 ***'
'With objCmd
' .Parameters.AddWithValue("@sCustomerID","C005")
' .Parameters.AddWithValue("@sName","Weerachai Nukitram")
' .Parameters.AddWithValue("@sEmail","[email protected]")
' .Parameters.AddWithValue("@sCountryCode","TH")
' .Parameters.AddWithValue("@sBudget","2000000")
' .Parameters.AddWithValue("@sUsed","1000000")
'End With
'*** Sample 2 ***'
With objCmd
.Parameters.Add(New SqlParameter("@sCustomerID","C005"))
.Parameters.Add(New SqlParameter("@sName","Weerachai Nukitram"))
.Parameters.Add(New SqlParameter("@sEmail","[email protected]"))
.Parameters.Add(New SqlParameter("@sCountryCode","TH"))
.Parameters.Add(New SqlParameter("@sBudget","2000000"))
.Parameters.Add(New SqlParameter("@sUsed","1000000"))
End With
objCmd.ExecuteNonQuery()
lblText.Text = lblText.Text & "- Record Inserted"
'*** FOR UPDATE ***'
'strSQL = "UPDATE customer SET Budget = @sBudget " & _
'" WHERE CustomerID = @sCustomerID "
'objCmd = New System.Data.SqlClient.SqlCommand(strSQL,objConn)
'With objCmd
' .Parameters.Add(New SqlParameter("@sBudget","4000000"))
' .Parameters.Add(New SqlParameter("@sCustomerID","C005"))
'End With
'objCmd.ExecuteNonQuery()
ASP.NET System.Data.SqlClient - Parameter Query (SqlParameter)
|
|
|
|
|
Date :
2017-09-06 13:36:17 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = txt_Username.text
cmd.Parameters.Add("@pass", SqlDbType.VarChar).Value = txt_Password.text
ผมลองแบบนี้ก็ยังไม่ได้เลยครับ..
|
|
|
|
|
Date :
2017-09-06 15:22:41 |
By :
tongchimlang |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แคป หน้า Error มาดูได้ไม๊ครับ
|
|
|
|
|
Date :
2017-09-06 15:58:21 |
By :
lamaka.tor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
รบกวนด้วยครับ ทำยังไงก็ยังไม่ได้เลยครับ..
|
|
|
|
|
Date :
2017-09-08 08:35:07 |
By :
tongchimlang |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาโค้ดทั้งหน้ามาแปะหน่อยครับ
|
|
|
|
|
Date :
2017-09-08 16:02:35 |
By :
OOP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|