 |
|
Incorrect syntax near 'SETEmp_ID'. มันError แบบนี้อ่ะคับ ไม่ทราบว่าต้องแก้ตรงไหน ช่วยทีคับ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Btnupdate_Click() Handles Btnupdate.Click
If TextID.Text = "" Or IsDataComplete() = False Then
Exit Sub
End If
Dim s As String
If Not (PictureBox1.Image Is Nothing) Then
s = ",Picture=@pic"
Else
s = ""
End If
sql = "UPDATE Employee SET" &
"Emp_ID=@id,Emp_Name= @name,Emp_Las = @last,Emp_Age = @age,Emp_Num = @num,Emp_Add = @add" & s
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("@id", TextID.Text)
command.Parameters.AddWithValue("@name", Textname.Text)
command.Parameters.AddWithValue("@last", Textlats.Text)
command.Parameters.AddWithValue("@age", Textage.Text)
command.Parameters.AddWithValue("@num", Textnum.Text)
command.Parameters.AddWithValue("@add", Textadd.Text)
If Not (PictureBox1.Image Is Nothing) Then
Dim byteArr() As Byte = ReadImage()
command.Parameters.AddWithValue("pic", byteArr)
End If
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("บันทึกการเปลี่ยนแปลงแล้ว")
UpdateBinding()
Else
MessageBox.Show("เกิดข้อผิดพลาด")
End If
End Sub
End Class
Tag : .NET, VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2013-02-16 17:41:16 |
By :
tumsonicsnk |
View :
757 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
sql = "UPDATE Employee SET" & <<<< มันจะได้ UPDATE Employee SETEmp_ID=.... นะครับ วรรคหลังคำว่า SET นิดนึงครับ
"Emp_ID=@id,Emp_Name= @name,Emp_Las = @last,Emp_Age = @age,Emp_Num = @num,Emp_Add = @add" & s
เทคนิคเล็กๆหากมัน error เรารู้ว่า error ที่ไหนก็ตั้ง break point ตรงนั้น แล้วก็ลอง add quick watch ดูตัวแปรที่เกี่ยวข้องกับส่วนที่ error
ทำให้เราหาจุด error ง่ายขึ้นนะครับ
|
 |
 |
 |
 |
Date :
2013-02-16 17:50:45 |
By :
คนงานตัดอ้อย |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
set กับ emp เว้นวรรคหรือยัง ดูรูปแบบดีก่อนครับ
|
 |
 |
 |
 |
Date :
2013-02-16 19:36:41 |
By :
thon1900 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub Btnupdate_Click() Handles Btnupdate.Click
If TextID.Text = "" Or IsDataComplete() = False Then
Exit Sub
End If
Dim s As String
If Not (PictureBox1.Image Is Nothing) Then
s = ",Picture=@pic"
Else
s = ""
End If
sql = "UPDATE Employee SET Emp_ID = @id, Emp_Name = @name,Emp_Las = @last,Emp_Age = @age,Emp_Num = @num,Emp_Add = @add" & s
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("@id", TextID.Text)
command.Parameters.AddWithValue("@name", Textname.Text)
command.Parameters.AddWithValue("@last", Textlats.Text)
command.Parameters.AddWithValue("@age", Textage.Text)
command.Parameters.AddWithValue("@num", Textnum.Text)
command.Parameters.AddWithValue("@add", Textadd.Text)
If Not (PictureBox1.Image Is Nothing) Then
Dim byteArr() As Byte = ReadImage()
command.Parameters.AddWithValue("pic", byteArr)
End If
If command.ExecuteNonQuery() = 1 Then
MessageBox.Show("บันทึกการเปลี่ยนแปลงแล้ว")
UpdateBinding()
Else
MessageBox.Show("เกิดข้อผิดพลาด")
End If
End Sub
End Class
ทำตามที่เสนอให้ทำแล้วคับแต่ก็ยังไม่ได้ เหมือนเดิมขอคำชี้แนะอีกหน่อยคับ
|
 |
 |
 |
 |
Date :
2013-02-16 22:56:20 |
By :
tumsonicsnk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|