Dim cn As New OleDbConnection
Dim c1As New OleDbCommand
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim ma As String
Dim conn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Vb2008\Vbb\Vbb\Hotel.accdb;Persist Security Info=False"
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim ab, a1 As String
cn.ConnectionString = conn
c2.Connection = cn
ab = ComboBox7.Text
Dim ydate As String = Format((DateTimePicker1.Value.Date()).AddDays(ma).AddYears(-543), "M/d/yyyy")
Dim xdate As String = Format(DateTimePicker1.Value.Date().AddYears(-543), "M/d/yyyy")
c2.CommandText = "SELECT ROom_id,Check_in,Check_out,STATUS FROM STATUS_ROom WHERE ROom_id = " + ab + " and Check_in = #" + xdate + "# and Check_out = #" + ydate + "# and STATUS = 'Busy'"
da.SelectCommand = c2
da.Fill(ds, "STATUS_ROom")
DataGridView1.DataSource = ds.Tables("STATUS_ROom")
Try
a1 = ds.Tables("STATUS_ROom").Rows(0)("STATUS").ToString
If a1 = "Busy" Then
MsgBox("ห้อง " + ComboBox7.Text + " ไม่ว่าง ในวันที่ " + xdate + " ถึง " + ydate)
Else
End If
Catch ex As Exception
'อันไม่ไม่เกี่ยวคับคือดึงค่ามาลงtextboxเฉยๆ
TextBox3.Text = ydate
TextBox1.Text = xdate
TextBox4.Text = ComboBox1.Text
TextBox5.Text = ComboBox2.Text
End Try
End Sub