Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I have a form with some textboxes to save data to a 2003 access db. The saving to db works 100 %. I then have the option to go to form 2, where I can search, from a textbox, data in a datagridview (which is bind to access db). The problem is that if I add a new line to the db, and want to search for it from the textbox in form2, then it does not show when searched for. It does however show, in the datagridview, when the form is loaded. Only when the app is published, again, then the last line will show when filtered. I have tried all the options for Dataviewrowstatus, but results is the same.
Code for saving to db:
VB
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Sir Hickman\Documents\Visual Studio 2019\Staff\Staff\Staff\ActionsData.mdb;"
                Dim con As OleDbConnection = New OleDbConnection(conString)
                Dim cmd As OleDbCommand
                Dim dt As DataTable = New DataTable()
                'SQL STMT
                Dim SQL As String = "INSERT INTO ActionsData(Staff_number,Employee_name,Warning_date,Warning_Action,Validity,Expiration,Upload) Values(Staff_number,Employee_name,Warning_date,Warning_Action,Validity,Expiration,Upload) "

                cmd = New OleDbCommand(SQL, con)
                'ADD PARAMETERS
                cmd.Parameters.AddWithValue("Staff_number", TextBox1.Text)
                cmd.Parameters.AddWithValue("Employee_name", TextBox2.Text)
                cmd.Parameters.AddWithValue("Warning_date", DateTimePicker1.Text)
                cmd.Parameters.AddWithValue("Warning_Action", ComboBox1.Text)
                cmd.Parameters.AddWithValue("Validity", ComboBox2.Text)
                cmd.Parameters.AddWithValue("Experiration", DateTimePicker2.Text)
                cmd.Parameters.AddWithValue("Upload", "Yes")

                'OPEN CONNECTION And INSERT
                Try
                    con.Open()
                    If cmd.ExecuteNonQuery() > 0 Then
                        Label9.Text = "Info Successfully Updated"
                    End If
                    con.Close()
                Catch ex As Exception
                    MsgBox(ex.Message)
                    con.Close()
                End Try

Code on textbox to filter datagridview:

VB
dv = New DataView(ActionsDataDataSet4.Tables(0), "Employee_name= '" & TextBox1.Text & "' ", "Employee_name", DataViewRowState.CurrentRows)
        DataGridView2.DataSource = dv


What I have tried:

Search and Filtering of datagridview, from textbox, does not include the last new entry to database.
Posted
Updated 10-May-20 8:47am
v2
Comments
Richard MacCutchan 11-May-20 3:52am    
You need to refresh the DataGridView after you add entries to the database.
Member 14773490 11-May-20 14:59pm    
I have added a Datagridview.Refresh on the Save button, the load of form2 and on the textbox2.change.
Not working.

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