Knowing how to add new fields to a Microsoft Office Access database table using Visual Basic.NET (VB.NET) can save you time when you need to alter a table. Access is a relational database management system used to design local databases. VB.NET is an object-oriented computer programming language commonly used by programmers for its ease of use. A table is used to store data using columns and rows similar to a spreadsheet.
- Skill level:
Other People Are Reading
Things you need
- Microsoft Visual Basic Express
Open Microsoft Visual Basic Express, and click "New Project..." in the left pane of your screen. Double-click "Console Application." Press "Ctrl" and "A" and then press "Delete" to remove the current code.
Copy and paste the following code to your "Module1.vb" module to execute a query and add two fields to the "Products" table in the Northwind database.
Module Module 1
Sub Main() Dim northwindConn As OleDbConnection Dim sqlComm As OleDbCommand Dim strSQL As String northwindConn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;") northwindConn.Open() strSQL = "ALTER TABLE Products " & _ "ADD COLUMN Product_I Text (30), Product_II Text (30);" sqlComm = New OleDbCommand(strSQL, northwindConn) sqlComm.ExecuteNonQuery() MsgBox("Added two fields successfully to the Products table.") northwindConn.Close() End Sub
Edit the following line of code and type the path to your database:
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;")
Press "F5" to run your program.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for