Add new fields in Visual basic.net in existing database with databinding approach
Considered you have an existing database with the column name First name, Last name, and Middle name.
Using the databiding approach in Visual Basic.Net to connect your database source.
Here are the following steps:
1. On your Solution Explorer click Data Source. If the Data Source is hidden, go to the Data in the menu above and click Add new DataSource.
2. Click database and connection string. Make sure to used Microsoft Access Database file because we are using OLE DB. Finally browse you file in directory of your computer where the file save.
3. Make sure that your database is close while trying to test your connection, when it happen, the error dialog box appear.
4. Click continue and proceed to OK.
5. While trying to next, another dialog box appear that ask if you want to copy your data file to your project. If YES, the new location of your database copied to the directory of your project and it is located to your bin directory in debug folder. If NO, the current directory will obtain your connection and data once the new records added.
6. After completed that section, check the box of your table which table do you want to used or check all.
7. And now new database added to your solution explorer.
8. Some common problem encountered while saving their input data is the lost of data in database once the program is close.
9. Configure your database connection. In solution explorer, click your database name, the yellow icon on your database. Once the yellow icon is click, go to your properties window and copy to output: copy if newer. With that, once the new data added to your database, the consistency will obtain every time you save new data to your database.
Now, if you want to add new field or column in your database. Follow the steps:
1. In your project name of your folder, we have 2 databases copied. First, it is in your project name and the other is in your debug directory in bin folder.
2. In your project name folder, that's the local copy of your database where you can modify and changes affects to your database. If any changes in your database on your project folder name, the update database will update on your database in debug directory in bin folder.
3. In debug folder. That's the location of your database where the new data are added.
4. Now, adding new column in your database is quite simple but you have to memorized the way to configured.
5. First, in your project name folder, locate your database name and double click. In your design view. Add new field or column the name of your column. Example "address".
6. Try to fill address in your datasheet view.
7. Next, in your solution explorer. Double click your DataSet.xsd.
8. In your DataSet table, right click and add new column. Let say "address".
9. After adding new column which is address. Right click on your TableAdapter and configure your query.
10. In SELECT statement. Specify which fields do you want to retrieve. In last section of your SELECT before FROM place comma (,) and your column name address.
11. If you want to see the output. Try to click query builder and execute query. Next until it finished. Note: do not change the fill method to maintain the fill data connection.
12. In you form, add new label and text from your toolbox. This textbox you are going to bind, the name is address base in your column name and change the label name to address in order to recognize.
12. In you form, add new label and text from your toolbox. This textbox you are going to bind, the name is address base in your column name and change the label name to address in order to recognize.
13. Now, you are going to bind your textbox address. Click the textbox you are going to bind, then locate the properties settings. In DataBindings, click the plus sign to expand. Click the Text in order to bind and click the plus sign in binding source and click which column you want to bind. In our example click address
14. Finally, run your program. The new record filled your textbox address.
15. If you notice, the database on your project name folder will copy the new column and data on your debug folder.