Cannot update database through data bound TextBox

Hi all,

simple example: I've added a TextBox on a form, have bound it's text property to Table1BindingSource - Column_ID.

Data source update mode is set to OnPropertyChanged.

Table1BindingSource has DBDataSet as it's data source, DBDataSet is connect to Access database db.mdb.

So, problem is, when I change content in TextBox and I leave it, changes are'nt saved to database db.mdb. As I close the main form and run project again, TextBox's content is always same-unchanged.

Plz, any idea to really bind the TextBox with database, including change-updates

Thanx



Answer this question

Cannot update database through data bound TextBox

  • Daniel T

    The reason for this is as follows:

    When you run your app a copy of the database, the mdf, is copied to the

    bin debug folder within your source code folder.

    When you are adding rows etc you are infact adding them to this copy of the database.

    To prevent this you need to select the database within the solution explorer and change the its propery from copy always to copy if newer.

    In doing this when you run the app the database will not be over written and the rows etc will be retained.

    If you need to see the rows etc within your database table within the design environment

    you will need to copy the database files from the debug folder into the main folder.

    Hope this helps

    Ron


  • Peter Elbern

    hi,

    you can use textbox1_leave event handler to achieve that , you dataset will be filled by your table adapter at the beginning and the connection will be closed so if you want to update you have to call the table adapter again, last thing you have to tell your binding source that there are some data changed to accept it like beginedit and endedit b4 calling your table adapter

    Hope that helps



  • NobodySpecial

    I had the same problem. I found that, while in the IDE, changes saved to the database were not being persisted from one program run to the next. This is because if you are running your program from within the IDE you are assumed to be doing program development and changes to your database are not saved.

    If you execute your project (.exe) from your project's /bin/debug folder your chages to the database will persist from one program execution to the next.

    Hope this helps.


  • Vijay Soma

    ron nash wrote:

    Thanks, but I have my database file in .\bin\debug so the .mdb file is not overwritten, the DataSet is connected right to the file. However changes are not saved to this file.


  • Tim Sneath

    shakalama wrote:

    Yes thanks, I've written to FormClosing event this:

    InfoBindingSource.EndEdit()

    InfoTableAdapter.Update(DataBaseDs.info)


  • Cannot update database through data bound TextBox