Solved

Visual Basic 2005 Updating database with Binding Navigator

Posted on 2006-07-12
6
319 Views
Last Modified: 2013-11-25
I have a simple form in VB2005.  I added a Binding source that connects to an Access Database and a Binding Navigator.  I dragged the data fields onto the form and can view and navigate the data.  I do not know how to change the data ie. Add Delete or Edit.  I understand that I am only changing the dataset.  I need to also update the database with the changes.  Also if possible can the changed be made w/o clicking an update button.  If not it's OK.  Thank you in advance!

0
Comment
Question by:dupont2406
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
Davidshc76 earned 500 total points
ID: 17105000
You need to create the command add, delete, update when u selec the database............ E.g..

DaGeneral = New OleDbDataAdapter()
DaGeneral.SelectCommand = New OleDbCommand("SELECT * FROM [TABLENAME]", g_objconn)

Dim CB As OleDbCommandBuilder
CB = New OleDbCommandBuilder(DaGeneral)
DaGeneral.InsertCommand = CB.GetInsertCommand()
DaGeneral.UpdateCommand = CB.GetUpdateCommand()
DaGeneral.DeleteCommand = CB.GetDeleteCommand()
DsGeneral = New DataSet()
DaGeneral.Fill(DsGeneral, "GENERAL")
GeneralTable = DsGeneral.Tables("GENERAL")
GenDatasource = New BindingSource(DsGeneral, "GENERAL")
GenDatasource.DataSource = GeneralTable

After change the data in binding fields (TextBox)
DaGeneral.Update --- update the database
DsGeneral.AcceptChanges()

0
 

Author Comment

by:dupont2406
ID: 17105415
What part of the form do I put this code?  ie. form load etc.

and do I need to write the connection string in code or is the binding source and navigator enough?
0
 
LVL 5

Expert Comment

by:Davidshc76
ID: 17105435
You can put this code in Form Load.....

1. build database connection string to the database... e.g. g_objconn
2. put the code suggest ....
3. binding the datasource to textbox
4. create a button for update...

**Note :- your table should have primary key define for commandbuilder ...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question