Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> C# >> How to create table in MS-Access database using C# code?
How to create table in MS-Access database using C# code?

Microsoft Access database is a database management system from Microsoft that combines the relational Microsoft Jet Database Engine with a graphical user interface and software-development tools. In this blog I will explain you how to create a table in MS-Access database. Let’s take a look on it.
Views: 3272     Comments: 0
by Arun Singh on 4/10/2012

How to create table in MS-Access database using C# code?

Microsoft Access database is a database management system from Microsoft that combines the relational Microsoft Jet Database Engine with a graphical user interface and software-development tools. In this blog I will explain you how to create a table in MS-Access database. Let’s take a look on it.

To create a table in MS-Access database, first of all you’ve an existence database file or you have to create a new database file. After creating the database file; just write the following line of code to create the table in MS-Access database.

Code for MS-Access 2003:

// Creating OLEDB connection string for Ms-Access 2003 database file

            OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= D:\\Arun Singh\\MsAccessFile\\MyDatabase1.mdb; OLE DB Services=-1");

            // Open the connection

            myConnection.Open();

            // Create Oledb command to execute particular query

            OleDbCommand myCommand = new OleDbCommand();

            myCommand.Connection = myConnection;

            // Query to create table with specified data columne

            myCommand.CommandText = "CREATE TABLE tblIdentityTesting([MyIdentityColumn] long, [Name] text)";

            myCommand.ExecuteNonQuery();

            MessageBox.Show("Table Created Successfully");


Code for MS-Access 2007:

// Creating OLEDB connection string for Ms-Access 2007 database file

            OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= D:\\Arun Singh\\MsAccessFile\\MyDatabase.accdb;Persist Security Info=False;");

            // Open the connection

            myConnection.Open();

            // Create Oledb command to execute particular query

            OleDbCommand myCommand = new OleDbCommand();

            myCommand.Connection = myConnection;

            // Query to create table with specified data columne

            myCommand.CommandText = "CREATE TABLE tblIdentityTesting([MyIdentityColumn] long, [Name] text)";

            myCommand.ExecuteNonQuery();

            MessageBox.Show("Table Created Successfully");


This is a brief description about on creating a table in MS-Access database using C# code. I hope this blog will help you in understanding that how to create a table in MS-Access database using C# code.
Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Arun SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2908
  
Copyright © 2013MindStick. All Rights Reserved.