 |
|
รบกวนช่วยแก้ Error Must declare the scalar variable "@id". ตรงนี้หน่อยคับผม |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub ButtonSave_Click() Handles ButtonSave.Click
If IsDataComplete() = False Then
Exit Sub
End If
sql = "INSERT INTO Employee "
If Not (PictureBox1.Image Is Nothing) Then
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add,Picture)" &
"VALUES(@id,@name,@last,@age,@num,@add,@pic)"
Else
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add)" &
"VALUES(@id,@name,@last,@age,@num,@add)"
End If
Dim command As New SqlCommand(sql, conection)
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("Emp_ID", TextID.Text)
command.Parameters.AddWithValue("Emp_Name", Textname.Text)
command.Parameters.AddWithValue("Emp_Las", Textlats.Text)
command.Parameters.AddWithValue("Emp_Age", Textage.Text)
command.Parameters.AddWithValue("Emp_Num", Textnum.Text)
command.Parameters.AddWithValue("Emp_Add", Textadd.Text)
If Not (PictureBox1.Image Is Nothing) Then
Dim pic() As Byte = ReadImage()
command.Parameters.AddWithValue("pic", pic)
End If
Dim result As Integer = command.ExecuteNonQuery()
If result = -1 Then
MessageBox.Show("เกิดข้อผิดพลาดไม่สามารถเพิ่มข้อมูลได้")
Else
MessageBox.Show("บันทึกข้อมูลแล้ว")
ButtonAdd.PerformClick()
End If
End Sub
Tag : .NET, VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2013-02-16 13:39:39 |
By :
TUM |
View :
2395 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub ButtonSave_Click() Handles ButtonSave.Click
If IsDataComplete() = False Then
Exit Sub
End If
sql = "INSERT INTO Employee "
If Not (PictureBox1.Image Is Nothing) Then
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add,Picture)" &
"VALUES(@id,@name,@last,@age,@num,@add,@pic)"
Else
sql &= "(Emp_ID,Emp_Name,Emp_Las,Emp_Age,Emp_Num,Emp_Add)" &
"VALUES(@id,@name,@last,@age,@num,@add)"
End If
Dim command As New SqlCommand(sql, conection)
command.Parameters.Clear()
command.CommandText = sql
command.Parameters.AddWithValue("Emp_ID", TextID.Text)
command.Parameters.AddWithValue("Emp_Name", Textname.Text)
command.Parameters.AddWithValue("Emp_Las", Textlats.Text)
command.Parameters.AddWithValue("Emp_Age", Textage.Text)
command.Parameters.AddWithValue("Emp_Num", Textnum.Text)
command.Parameters.AddWithValue("Emp_Add", Textadd.Text)
If Not (PictureBox1.Image Is Nothing) Then
Dim pic() As Byte = ReadImage()
command.Parameters.AddWithValue("pic", pic)
End If
Dim result As Integer = command.ExecuteNonQuery()
If result = -1 Then
MessageBox.Show("เกิดข้อผิดพลาดไม่สามารถเพิ่มข้อมูลได้")
Else
MessageBox.Show("บันทึกข้อมูลแล้ว")
ButtonAdd.PerformClick()
End If
End Sub
|
 |
 |
 |
 |
Date :
2013-02-16 13:59:13 |
By :
tumsonicsnk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ok คับ ได้แล้วคับผม ขอบคุณคับ
|
 |
 |
 |
 |
Date :
2013-02-16 14:03:53 |
By :
tumsonicsnk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|