Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A better way is to create an SQL query that will <a href="http://www.w3schools.com/sql/sql_join_inner.asp" rel="nofollow"><strong>join</strong></a> the tables based on the Employee ID field and will filter the data based on the date field. The DataGridView will be binded to a DataTable which will be filled based on that SQL query.</p> <p>Sample code :</p> <pre><code>Dim FilterStr1 As String = "03/01/2013" Dim DBPathStr1 As String = "C:\db1.mdb" Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim SqlConnStr1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &amp; DBPathStr1 &amp; ";" Dim SqlStr1 As String = &lt;SQL&gt; SELECT W.[Date] ,W.[Employee ID] ,W.[Activity] ,W.[Hours worked] ,W.[Department] ,W.[Shift] ,W.[Equipment Used] ,E.[Name] ,E.[Middle] ,E.[Last] FROM [Work] AS W INNER JOIN [Employees] AS E ON W.[Employee ID] = E.[Employee ID] WHERE W.[Date] = #&lt;%= FilterStr1 %&gt;# &lt;/SQL&gt;.Value Dim OleDBAdap1 As New OleDbDataAdapter(SqlStr1, SqlConnStr1) Dim SqlDTable1 As New DataTable OleDBAdap1.Fill(SqlDTable1) DataGridView1.DataSource = SqlDTable1 OleDBAdap1.Dispose() End Sub </code></pre> <p>To use this code you will need to change the value of the variable <code>DBPathStr1</code> with the path of your MS Access Database and set a date value for the <code>FilterStr1</code> variable. </p> <p><strong>EDIT</strong></p> <p>The value of the <code>FilterStr1</code> variable can be assigned by using a DateTimePicker control. To do that you will need to add a DateTimePicker control on the form and add the following code.</p> <pre><code>Private Sub DateTimePicker1_ValueChanged(sender As System.Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged FilterStr1 = DateTimePicker1.Value.ToString("dd/MM/yyyy") End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload