I use
dim mydb as recordset
and also use
mydb.update
in certain required places like the update command button clicking. It works, by adding the new value in database. I have a list that shows the values of that db. But the main problem is i cannot see the newly added values unless i exit and reopen the application. after reopen i can see the newly added value. But i want to see the value in run time after clicking the add button which add value from a text box that i write. Sorry for the long literature, please help me.

Dani AI

Generated

The behaviour described by — the new row is written to the database but does not appear in the UI until the app restarts — means the UI is still showing a cached result. The suggestions already posted are on the right track: as noted, reloading the data source works; pointed to requerying the recordset; supplied a DAO-based approach; and correctly flagged that the solution depends on whether you are using DAO, ADO or VB.NET data binding.

If the project uses classic ADO (VB6), the simplest, reliable pattern is: perform the insert/commit, then re-run a SELECT and repopulate the list control rather than relying on the old in-memory set. Example pattern (VB6 + ADO):

' VB6 + ADO: re-fill a ListBox after the insert
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;"
rs.Open "SELECT name FROM table1 ORDER BY id", cn, adOpenForwardOnly, adLockReadOnly

List1.Clear
Do While Not rs.EOF
  List1.AddItem rs.Fields("name").Value
  rs.MoveNext
Loop

rs.Close
cn.Close

For VB.NET/WinForms with data binding, call the adapter/fill again or reset the binding source after the insert so the bound control picks up changes:

' VB.NET: refill a DataTable and rebind
Using cn As New SqlConnection(connString)
  Dim da As New SqlDataAdapter("SELECT id,name FROM table1 ORDER BY id", cn)
  Dim dt As New DataTable()
  da.Fill(dt)
  ListBox1.DataSource = dt
  ListBox1.DisplayMember = "name"
End Using

Quick troubleshooting tips: make sure any transaction is committed before re-reading, clear the control before repopulating, and for large tables prefer inserting the new row into the UI directly (if you know its values and ID) rather than requerying the whole table.

Recommended Answers

All 6 Replies

try list1.refresh after the updating part,

but sometimes this does not work.
Best way,after updating,close the connection then open it again,ok?

As i am not so expert, would u please tell me what should be the code example of closing connection?

mydb.close

What is the type of connection that you are using.

if u r using the DAO technique use the table recordset type at the time of opening the recordset. a sample is :-

dim db as database,rs as recordset

set db=opendatabase(app.path & "\mydb.mdb")
set rs=db.openrecordset("table1",dbopentable)
if rs.recordcount>0 then
''ur data showing code goes here
endif

otherwise u have to simultaneously unload and show up ur forms.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.