Database update

Mike.m

New member
Joined
Feb 18, 2010
Messages
2
Programming Experience
Beginner
i have just started using databases with ADO.net and i am not the best programmer in the world so i was pleasantly suprised when Visual Studio seemed to build everything for me.
I added my Access file using add new data source and went through the wizard and everything seemed to work fine apart from updating back to the original database, it looks like it works and i close and re-open VB a few times then it just goes back to the old database. Can somebody see where i am going wrong or point me in the right direction also is it possible to add a query that will search for names I am able to sort the data but not do specific searches for names or addresses.

VB.NET:
Public Class Form1

    Private Sub Members_ScreenBindingNavigatorSaveItem_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Members_ScreenBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.Members_ScreenBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Members11DataSet)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Members11DataSet.Members_Screen' table.
        ' You can move, or remove it, as needed.
        Me.Members_ScreenTableAdapter.Fill(Me.Members11DataSet.Members_Screen)

    End Sub

    
    Private Sub btnend_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles btnend.Click
        End
    End Sub

thxs for any help or cmments.
 
Most likely your Access Database .mdb file in your project has it's Copy to Output Directory property set to Copy Always. Change it to either Copy if newer or Do not copy. Copy if newer is recommended if you plan to make changes to the database. If you use Do not copy and make a change to the database, you'll either have to manually copy the database to the output directory, or change the property to one of the other values for a build.

There are several ways to perform a search and the best depends on the situation. The two main options are to filter the data you have already queried from the database, or execute another query, pulling only the data you want. The best method will depend on many things including the quantity of data being filter or returned by the query.

To filter the data you already have in the DataSet, simply set the Filter property of the BindingSource. Since you say you have just started using databases with ADO.NET, I very strongly recommend you stay away from Access. Instead use MS SQL Server Express. It's free and distributable, more tightly integrated with Visual Studio, and has more features than Access.
Access uses a different SQL syntax than most other database types. For the search to work, use a Filter value similar to this:
VB.NET:
BindingSource.Filter = String.Format("(FirstName LIKE '%{0}%') OR (LastName LIKE '%{0}%')", txt)
where txt could be the Text value of a TextBox. Setting the Filter value in the TextBox's KeyPressed event will allow 'auto' filtering.
 
thxs for the reply i managed to get the database to update i hope by changing to copy if newer, i forgot to mention i am not that good at VB but i enjoy learning. the search option i will need to work on i have an old phone book program but im told that is what it is old, the ADO.net is good although i did not have to do any coding myself and i used access as i know how to make databases in that i will download the MS SQL and look at that especially if it will make things easier.

My next project is linking a log in screen to the addrress book so i will prob be around asking more questions but the help here is very much appreciated :D
 
thxs for the reply i managed to get the database to update i hope by changing to copy if newer
The database was always updating; it's just that a setting of "Copy Always" causes a fresh copy of your clean DB to overwrite the one you just updated.. A small and confusing but important distinction.. )
 
Back
Top