Question Data not updated until restart

thek

Member
Joined
May 31, 2009
Messages
22
Programming Experience
Beginner
Hi.

When I add a new entry in a access database via the GUI, the vb.net program must be restartet before I can see the data in the GUI.

1. Why?
2. How to fix it?

Thanks

VB.NET:
Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsNewRow As DataRow

            dsNewRow = ds.Tables("MyTabel").NewRow()

            dsNewRow.Item("Email") = txtEmail.Text
            dsNewRow.Item("Name") = txtName.Text

            ds.Tables("MyTabel").Rows.Add(dsNewRow)
            da.Update(ds, "MyTabel")
 
I have allready looked there, because when I searched the forum, you have reply others with the same reply.

But there are a lot of walkthroughs. Can you point me to the right one?
 
No help in your links.

Maybe I didn't make myself clear, but I have made the vb.net application manualy, and not via the "drag'n drop" tools, becuase I need to show data in custom fields and controls.

The above code updates the database with new information and stores it, but the new data is not shown in my application. I have to close the application and open it again, before the new data is shown.

Somehow I need to "form_load" the entire application, without closing it or re-fresh the database via the application (I prefer the last option)
 
The data will be displayed in any controls that are bound to the DataTable you added the row to. If you're not seeing the data then I can only assume that you haven't bound that DataTable to any controls.
 
No help in your links.
If you'd done stuff as described in the links, then you wouldnt have any problem
icon12.gif



Maybe I didn't make myself clear, but I have made the vb.net application manualy, and not via the "drag'n drop" tools, becuase I need to show data in custom fields and controls.
Nothing stopping you doing that after following the links though..
icon12.gif


The above code updates the database with new information and stores it, but the new data is not shown in my application. I have to close the application and open it again, before the new data is shown.
As JMC points out, youre putting data into a datatable that isnt linked to the display (because you wanted to do it yourself because you have custom controls) and pushing to the database. Hence, theres a disconnect: the only time you show things on screen is when you download them from a database, the only time you download from a database is in form_load and youre now complaining that changes you made to the database that you didnt download are not being shown

Somehow I need to "form_load" the entire application, without closing it or re-fresh the database via the application (I prefer the last option)
The preferred option is to have a local cache of data that you show, update and send back to the database; after all, you don't reopen a word document every time you save it :)
 
Yes, I'm aware that if I follow the step-by-step solution, then It's working correct, but the reason for my post is that it's not working when I created the code myself, and I need help :p

What I would like is the (I pretty sure it's simple) code for the dataset to update the database. Then Open() Close() to get the new database again, for display in the GUI.

The problem is if I add this:

VB.NET:
Public Sub Database_load()
        dbProvier = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = C:\testDB.mdb"
        con.ConnectionString = dbProvier & dbSource
        con.Open()
        sql = "SELECT * FROM SpilDATA"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "SpilDATA")
        con.Close()
        End Sub

And then add this in Form_load

VB.NET:
Database_load()

And then again in the bottom here:


VB.NET:
       Dim cb As New OleDb.OleDbCommandBuilder(da)
                Dim dsNewRow As DataRow

                dsNewRow = ds.Tables("SpilDATA").NewRow()

                dsNewRow.Item("SPIL") = txtSPIL.Text
                dsNewRow.Item("CreatedBy") = txtCreatedBy.Text
                dsNewRow.Item("Assign") = txtAssign.Text
                dsNewRow.Item("Severity") = cboSeverity.Text


                ds.Tables("SpilDATA").Rows.Add(dsNewRow)
                da.Update(ds, "SpilDATA")
                [B]Database_load()[/B]



Then the records are dobble, in the GUI. :eek:

Thanks.
 
Last edited:
.....youre now complaining that....

I'm not complaning, I'm asking for help. :D

I've ready your link, I've read the database sections in VB 2005 and VB for dummies, and servel articles on the net, but no luck.

And what more confuses me, is that I have an EDIT and DEL button as well.

When editing a record via gui, then it’s updated – without a new load from the database
When deleting a record via gui, then it’s removed – without a new load from the database


That's why I'm asking here.
 
Last edited:
If you're loading the data in your Load event handler and you want to be able to load the data elsewhere too then just take the code out of the Load event handler and put it into a method that you can call from anywhere.
 
If you're loading the data in your Load event handler and you want to be able to load the data elsewhere too then just take the code out of the Load event handler and put it into a method that you can call from anywhere.

Then the records are duplicated, in the GUI (e.g they are there twice)
 
ClearBeforeFill is a property of a strongly typed data adapter, ie a TableAdapter, which causes the code to call dataTable.Clear before each filling.

I agree with the others here that you're taking the wrong approach to learn data access, the easier beginner start is to use the Visual Studio wizards. You know you can read the code it generates afterwards, if you wish to see 'how it's done in code' ?
 
I agree with the others here that you're taking the wrong approach to learn data access, the easier beginner start is to use the Visual Studio wizards.

Hi guys

I agree. I'll create a new tread to taking it from the start

Thanks for your help (all of you)

Kind regards,
thek
 
Back
Top