Dim sql As String
sql = "SELECT tbl_DailyRecord.LabourID, tbl_DailyRecord.Nameeng, tbl_DailyRecord.Dates, tbl_DailyRecord.TimeIn, tbl_DailyRecord.TimeOut, tbl_DailyRecord.Hours FROM tbl_DailyRecord"
If CheckBox1.Checked Then
Dim a As String = DateTimePicker1.Value
Dim b As String = DateTimePicker2.Value
sql = " Where tbl_DailyRecord.Dates between #" & a & "# AND tbl_DailyRecord.Dates #" & b & "#"
End If
sql &= " order by tbl_DailyRecord.LabourID"
da = New OleDbDataAdapter(sql, conn)
ds = New DataSet
da.Fill(ds, "labour")
DataGridView1.Rows.Clear()
If ds.Tables(0).Rows.Count <> 0 Then
For i = 0 To ds.Tables(0).Rows.Count - 1
DataGridView1.Rows.Add()
DataGridView1.Rows(i).Cells("LabourID").Value = ds.Tables(0).Rows(i).Item("LabourID").ToString
DataGridView1.Rows(i).Cells("Nameeng").Value = ds.Tables(0).Rows(i).Item("Nameeng").ToString
DataGridView1.Rows(i).Cells("Dates").Value = ds.Tables(0).Rows(i).Item("Dates")
DataGridView1.Rows(i).Cells("TimeIn").Value = ds.Tables(0).Rows(i).Item("TimeIn")
DataGridView1.Rows(i).Cells("TimeOut").Value = ds.Tables(0).Rows(i).Item("TimeOut")
DataGridView1.Rows(i).Cells("Hours").Value = ds.Tables(0).Rows(i).Item("Hours")
Next
End If
SELECT tbl_DailyRecord.LabourID, tbl_DailyRecord.Nameeng, tbl_DailyRecord.Dates, tbl_DailyRecord.TimeIn, tbl_DailyRecord.TimeOut, tbl_DailyRecord.Hours
FROM tbl_DailyRecord Where tbl_DailyRecord.Dates Between #20/11/2012 00:00:00# And #20/11/2012 23:59:59 #
Code (VB.NET)
Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
Dim da_mem As New SqlDataAdapter
Dim ds_mem As New DataSet
Dim sql As String
sql = "SELECT * from tmember where memname like '%" & Textbox1.Text & "%' "
da_mem.SelectCommand = New SqlCommand(Sql, Conn)
ds_mem.Clear()
da_mem.Fill(ds_mem, "tmember")
bs.DataSource = ds_mem.Tables("tmember")
dgvMember.DataSource = bs
End Sub