Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If DataGridView1.RowCount = 0 Then
MsgBox("No data to Edit", MsgBoxStyle.Critical, "Err")
Exit Sub
End If
If Trim(TextBox1.Text) <> "" And (Trim(TextBox5.Text) <> "" Or Trim(TextBox6.Text) <> "") Then
Try
cmd.Connection.Close()
cmd.CommandText = "UPDATE Product SET [PID] = '" & TextBox1.Text & "',[ชื่อสินค้า] = '" & TextBox5.Text & "',[จำนวน] = '" & TextBox6.Text & "',[ราคาต้นทุน] = '" & TextBox2.Text & "',[ราคาขาย] = '" & TextBox3.Text & "',[หน่วย] = '" & TextBox4.Text & ""
cmd.Connection.Open()
[color=yellow] cmd.ExecuteNonQuery()
Call FillDGV()
afftersave()
MsgBox("data has been modified successfully", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "cancle")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Else
MsgBox("Please enter correct data", MsgBoxStyle.Critical, "Err")
Exit Sub
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Trim(TextBox1.Text) <> "" And (Trim(TextBox5.Text) <> "" Or Trim(TextBox6.Text) <> "") Then
Try
cmd.Connection.Close()
cmd.CommandText = "Insert Into product([PID],[ชื่อสินค้า],[จำนวน],[ราคาต้นทุน],[ราคาขาย],[หน่วย]) Values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
cmd.Connection.Open()
cmd.ExecuteNonQuery()
Me.Close()
MsgBox("The data was saved successfully", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "Saving Is Completed")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Else
MsgBox("Please Enter data", MsgBoxStyle.Critical, "Err")
Exit Sub
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Trim(TextBox1.Text) <> "" And (Trim(TextBox5.Text) <> "" Or Trim(TextBox4.Text) <> "") Then
Try
cmd.Connection.Close()
cmd.CommandText = "Insert Product SET [ชื่อสินค้า]='" & TextBox1.Text & "',[จำนวน]='" & TextBox2.Text & "',[ราคาต้นทุน]='" & TextBox3.Text & "',[ราคาขาย]='" & TextBox4.Text & "',[หน่วย]='" & TextBox5.Text & "' "
cmd.Connection.Open()
cmd.ExecuteNonQuery()
Me.Close()
MsgBox("The data was saved successfully", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "Saving Is Completed")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Else
MsgBox("Please Enter data", MsgBoxStyle.Critical, "Err")
Exit Sub
End If
End Sub
ลองแล้วครับแต่มันไม่ได้อะครับ ลองเปลี่ยนชื่อ field เป็นภาษาอังกฤษแล้วก็ยังไม่ได้ครับ
Code (VB.NET)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Trim(TextBox1.Text) <> "" And (Trim(TextBox5.Text) <> "" Or Trim(TextBox4.Text) <> "") Then
Try
cmd.Connection.Close()
cmd.CommandText = "Insert Into Product([ProductName],[Amount],[Costprice],[Sellingprice],[Unit])Values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "') "
cmd.Connection.Open()
cmd.ExecuteNonQuery()
Me.Close()
MsgBox("The data was saved successfully", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "Saving Is Completed")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Else
MsgBox("Please Enter data", MsgBoxStyle.Critical, "Err")
Exit Sub
End If
End Sub