Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Sunday, 7 February 2016

How to Add Fields to a Table in Access with Visual BasicIn Feburary 2016 07,

In Feburary 2016 07,
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.Imports System.Data.OleDbModule Module1
Sub Main()Dim northwindConn As OleDbConnectionDim sqlComm As OleDbCommandDim strSQL As StringnorthwindConn = 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
End Module
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.
In Feburary 2016 07,