Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my form I have 3 textboxes in which i want to be able to enter data, press enter and it should search the word
textbox1 = name or surname
textbox2 = researchtype
textbox3 = diagnosetype.

the dataset gets loaded when i open the form
this is the code for that part:

Public Class Dossiers
    Private Sub Dossiers_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim str As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb"
        Dim con As New OleDbConnection(str)
        Dim com As String = "Select          tbl_Dossiers.Dos_ID, tbl_Relaties.Rel_Naam, tbl_Relaties.Rel_Voornaam, tbl_Onderzoekstypes.OZ_TypeOnderzoek, tbl_Diagnoses.Diag_Type
                               FROM((((tbl_Dossiers 
                               Left OUTER JOIN tbl_DossRelatie ON tbl_Dossiers.Dos_ID = tbl_DossRelatie.DR_DossID) 
                               Left OUTER JOIN tbl_Relaties ON tbl_DossRelatie.DR_RelID = tbl_Relaties.Rel_ID) 
                               Left OUTER JOIN tbl_OnderzoeksTypes ON tbl_Dossiers.OZ_ID = tbl_OnderzoeksTypes.OZ_ID) 
                               Left OUTER JOIN tbl_Diagnoses ON tbl_Dossiers.Diag_ID = tbl_Diagnoses.Diag_ID)
                               ORDER BY        tbl_Dossiers.Dos_ID"
        Dim adpt As New OleDbDataAdapter(com, con)
        Dim dossierset As New DataSet()
        adpt.Fill(dossierset, "Dos_ID")
        dgvDossiers.DataSource = dossierset.Tables(0)
        dgvDossiers.Show()

    End Sub



I've tried 2 approaches so far, and google tells me about the same...:

What I have tried:

Private Sub Pat_VoornaamTextBox_KeyDown(sender As Object, e As KeyEventArgs) Handles Pat_VoornaamTextBox.KeyDown
    If e.KeyCode = Keys.Enter Then
        Dim dv As DataView
        dv = New DataView(Dossierset.Tables(0), "Rel_Naam= '" & Me.Pat_VoornaamTextBox.Text & "' ", "Rel_Naam", DataViewRowState.CurrentRows)
        Me.DGVDossiers.DataSource = dv
    End If
End Sub


'Try
'bindingsourceDossier.Filter = "Rel_Naam like '" & Pat_VoornaamTextBox.Text & "%'" &
'        " OR Rel_Voornaam like '" & Pat_VoornaamTextBox.Text & "%'"
'Catch ex As Exception
' MessageBox.Show("Er is een fout opgetreden: " & ex.Message.ToString(),
'                    "Zoek Relatie", MessageBoxButtons.OK, MessageBoxIcon.Error)
'End Try
Posted
Updated 4-Nov-20 23:18pm

Try this:
If e.KeyCode = Keys.Enter Then
  Dim table = Dossierset.Tables(0)
  table.DefaultView.RowFilter = "Rel_Naam= '" & Me.Pat_VoornaamTextBox.Text & "'"
  Me.DGVDossiers.DataSource = table
End If

You probably also need to declare table as a Public variable.
 
Share this answer
 
Comments
Izzy Decorte 5-Nov-20 4:48am    
Hi Rick,
It doesn't seem to work.
Private Sub Pat_VoornaamTextBox_KeyDown(sender As Object, e As KeyEventArgs) Handles Pat_VoornaamTextBox.KeyDown
If e.KeyCode = Keys.Enter Then
Dim Dossierset As New DataSet()
Dim table = Dossierset.Tables(0)
table.DefaultView.RowFilter = "Rel_Naam= '" & Me.Pat_VoornaamTextBox.Text & "'"
Me.DGVDossiers.DataSource = table
End If
End Sub
this is what i did but i get errors
I think i need some kind of binding source?
RickZeeland 5-Nov-20 4:52am    
I'll try over here, but my VB skill are very rusty :)
RickZeeland 6-Nov-20 1:08am    
And, did you try Solution 2 ? it should work even without a bindingsource.
A small example adapted from https://www.dotnetperls.com/dataset-vbnet[^]
Public Class Form1
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Module1.Main()
        Me.DataGridView1.DataSource = set1.Tables(0)
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        set1.Tables(0).DefaultView.RowFilter = "name = 'sam'"
        Me.DataGridView1.DataSource = set1.Tables(0)
    End Sub
End Class

Module Module1
    Public table1 As DataTable = New DataTable("patients")
    Public table2 As DataTable = New DataTable("medications")
    Public set1 As DataSet = New DataSet("office")

    Sub Main()
        ' Two DataTables.
        table1.Columns.Add("name")
        table1.Columns.Add("id")
        table1.Rows.Add("sam", 1)
        table1.Rows.Add("mark", 2)

        table2.Columns.Add("id")
        table2.Columns.Add("medication")
        table2.Rows.Add(1, "atenolol")
        table2.Rows.Add(2, "amoxicillin")

        ' Create a DataSet. Put both tables in it.
        set1.Tables.Add(table1)
        set1.Tables.Add(table2)

        ' Visualize DataSet.
        Debug.WriteLine(set1.GetXml())
    End Sub
End Module
 
Share this answer
 
v3
Comments
Izzy Decorte 7-Nov-20 8:21am    
Hey Rick, The code example you made works, but it seems i'm not smart enough to implement it in my existing code. I've tried for an entire day but to no avail.
RickZeeland 7-Nov-20 8:35am    
Ah well, wisdom comes with the ages :)
Izzy Decorte 7-Nov-20 9:51am    
thanks for the input

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900