C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Create a table in MS Access Database using SQL via VB.NET


Posted Date: 01 Nov 2004    Resource Type: Articles    Category: .NET Framework
Author: Pete*Member Level: Gold    
Rating: 1 out of 5Points: 7



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
--------------------------




Responses

Author: alfu meah    08 Mar 2005Member 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 2005Member 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 2009Member Level: Bronze   Points : 1
This is great. How do you add and change column or field properties in code?


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Notification Services (.NET and MS SQL Server)
Previous Resource: Read Data out of MS Access Database into text box
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use