Database Tutorial for Visual Basic 2008
- 1). Create a database of information in Microsoft Access if you haven't done so already. Make sure the headings of the columns are what you want your users to reference the information by. For example, if you're building a place to store addresses and phone numbers, label the columns "Address" and "Phone Number" not "Coulumn2" or "Column3." Double-check the rest of the information for accuracy.
- 2). Open your developer environment. Click "Project" next to "Create" in the upper left hand corner of your screen. Choose "Windows Form Application" from the choices in the new window and type the name of your new Visual Basic application in the "Name" box down below. Click "OK" when you finish.
- 3). Drag a "Label" box from the "Tool Box" on the left hand side of your screen to the blank form to the right. Click on the "Label" once and then click on the "Properties" tab on the right hand side of the screen. Change the "Text" property to include any helpful instructions to the user such as, "Click on the field you want to search by..." and hit "Enter" when you finish.
- 4). Click and drag a "Data Grid View" display item to the form. This is what your database information will display in once it's linked up. Navigate to the top menu choices and click on the word "Data" then choose "Add New Data Source." A window will open up with "Database" already highlighted. Click "Next." Click "New Connection." Choose "Browse" and navigate to the location on your hard drive that contains your database. Click on the file and choose "Test Connection" and then click on "OK" to return you to the developer environment.
- 5). Click on the "Data Grid View" in the middle of your form. Notice the little "arrow" along the top border. Click on the little "arrow" to expand it. Click on "Edit columns" and view them to make sure they look correct. If you find errors in how the headings appear, you'll be able to fix it from this screen. Close the screen when you are finished.
- 6). Click and drag a "Table Adapter" from the "Tool Box" and place it on the work grid. Double-click on the "Tab Adapter" icon at the bottom of the grid to take you to the coding screen. Declare the name of your database such as "Dim customerInformationDatabase as New CustomerInformationDatabaseSet()" without the outer quotation marks. Set the database to the "Table Adapter" by typing "Dim customerInformationTableAdapter as New CustomerInformationDatabaseTableAdapter.CustomerInformationDatabaseSet()" without the quotation marks. To update a field in the customer database, type the syntax in the following format replacing the "Nameof" spots with the names of your files, "Me.NameofTableAdapter.Update(Me.NameofDatabaseSet.FieldinDatbase)" without the added quotation marks. Keep adding code to make the database work. The code you will use will vary widely depending on your circumstances and needs.
- 7). Run your Visual Basic database project by clicking on the "green arrow" pointing to the right along the top icon choices at the top of the screen. Test your application and correct any errors you may find.