Create a table in MS Access Database using SQL via VB.NET -------------------------- -------------------------- VB.NET Code -------------------------- -AT THE TOP OF THE PAGE, INSERT THE FOLLOWING LINE-
Imports System.Data.OleDb -----------------------------------------
'MAIN CODE'
Dim Cmd As OleDbCommand Dim SQL As String Dim objCmd As New OleDbCommand
Dim Con = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source=" & Database & "")
SQL = "CREATE TABLE tbCatalogue ([Id] COUNTER, [Stock Code] TEXT(10), [Account Number] TEXT(6))" Cmd = New OleDbCommand(SQL, Con)
Con.Open() objCmd = New OleDbCommand(SQL, Con) objCmd.ExecuteNonQuery() Con.Close()
-------------------------- Quick explanation -------------------------- First I'm Importing the Namespace that I want to use into the project. Then I'm creating the MS Access database connection. Next I'm Creating the SQL query to create a new table in my Access database called 'tbCatalogue'. Finaly I'm opening the connection to the database, executing the the SQL command/query, and then closing the database connection. -------------------------- Summary -------------------------- Yes, I could make this code shorter quite easily but I like my code looking this way for ease of reading.
ENJOY
Pete* ;-) UK --------------------------
|
| Author: alfu meah 08 Mar 2005 | Member Level: Bronze Points : 0 |
excellent tutorial. just tried your code. works perfect. beutifully written. hope you put on more scripts. im new to vb.net and find this very easy to understand.
|
| Author: Henian Li 11 Mar 2005 | Member Level: Bronze Points : 0 |
I am interested in how to bcp into Access from VB.NET. Insert the rows one by one or anything good method? Thank in advance.
hli
|
| Author: George Viveiros 18 Jun 2009 | Member Level: Bronze Points : 1 |
This is great. How do you add and change column or field properties in code?
|