Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
If txtidres.Text.Trim() = "" Then
MessageBox.Show("กรุณากดเพิ่มใบจองก่อน!!", "ตรวจสอบข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If MessageBox.Show("คุณต้องการเพิ่มใบจองใช่หรือไม่", "ตรวจสอบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
Exit Sub
End If
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Dim sqlSave As String
sqlSave = "Insert Into Reservation(res_ID,panel_Id,res_Date,cus_id,emp_id,Deposit)"
sqlSave &= "values(@id,@panel,@date,@cus,@emp,@deposit)"
Dim cm As New SqlCommand
With cm
.CommandType = CommandType.Text
.CommandText = sqlSave
.Connection = cn
.Parameters.Clear()
.Parameters.AddWithValue("@id", txtidres.Text)
.Parameters.AddWithValue("@panel", txtidpanel.Text)
.Parameters.AddWithValue("@date", DateTimePicker1.Value)
.Parameters.AddWithValue("@cus", txtidcus.Text)
.Parameters.AddWithValue("@emp", txtempid.Text)
.Parameters.AddWithValue("@deposit", txtmoney.Text)
.ExecuteNonQuery()
sqlSave = "SELECT * from Rent R,panel P"
sqlSave &= " WHERE R.panel_id ='" & txtidpanel.Text & "'"
sqlSave &= " AND P.status_panel= 3 "
End With
showData()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว")
Clear()
End Sub
Tag : Ms SQL Server 2008, VB.NET, VS 2008 (.NET 3.x)
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
If txtidres.Text.Trim() = "" Then
MessageBox.Show("กรุณากดเพิ่มใบจองก่อน!!", "ตรวจสอบข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If MessageBox.Show("คุณต้องการเพิ่มใบจองใช่หรือไม่", "ตรวจสอบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
Exit Sub
End If
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Dim sqlSave As String
sqlSave = "Insert Into Reservation(res_ID,panel_Id,res_Date,cus_id,emp_id,Deposit)"
sqlSave &= "values(@id,@panel,@date,@cus,@emp,@deposit)"
sqlSave = "update Panel Set status_panel ='3' Where status_panel = 'txtidpanel.Text '" 'แก้ไขตรงส่วนโค้ดนี้
Dim cm As New SqlCommand
With cm
.CommandType = CommandType.Text
.CommandText = sqlSave
.Connection = cn
.Parameters.Clear()
.Parameters.AddWithValue("@id", txtidres.Text)
.Parameters.AddWithValue("@panel", txtidpanel.Text)
.Parameters.AddWithValue("@date", DateTimePicker1.Value)
.Parameters.AddWithValue("@cus", txtidcus.Text)
.Parameters.AddWithValue("@emp", txtempid.Text)
.Parameters.AddWithValue("@deposit", txtmoney.Text)
.ExecuteNonQuery()
End With
showData()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว")
Clear()
End Sub