Solved

Visual Basic 2005 Updating database with Binding Navigator

Posted on 2006-07-12
6
317 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now