Click here to Skip to main content
11,705,119 members (46,671 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Application
Hi Friends ,

I am New To Windows Application, i wanna Export Sql Database Tables to Access MDB File using C sharp Coding in Windows Application , so can any help me for the Same . Thanks in Advance.

Regards,
Saravana Kumar.M
Posted 24-Oct-12 20:39pm
Comments
sinhasourabh at 25-Oct-12 2:41am
   
try to use import data feature of access.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
 
Open sql Server Management Studio and follow the following steps
 
   - Right Click on Database GoTo Task -> Export Data
 
   - In the choose a source scree
       - Select source database and provide the credentials 
       - Press Next
 
   - In the choose a destination screen
       - Select Destination as Microsoft Access
       - Provide a file Path. User id and password if you want to configure
 
   - Select option as copy data from one or more table or view and say next
 
   - you will see all the tables in database select the respective tables 
     which you want to export and finish
   
It will export the respective tables in the mdb file.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try the following snippette:

//Using JET.OLEDB :
System.Data.OleDb.OleDbConnection AccessConn = new 
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Test Files\\db1.mdb");
 
//Using ACE.OLEDB :
//System.Data.OleDb.OleDbConnection AccessConn = new
//System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Test Files\\db1.mdb")

AccessConn.Open();
 
//New table, using SELECT INTO
System.Data.OleDb.OleDbCommand AccessCommand = new System.Data.OleDb.OleDbCommand("SELECT * INTO Orders FROM [Orders] IN '' [ODBC;Driver={SQL Server};Server=(local);Database=Northwind;Trusted_Connection=yes];", AccessConn);
 
//Existing table, using INSERT INTO 
//Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [ORDERS] SELECT * FROM [Orders] IN '' //[ODBC;Driver={SQL Server};Server=(local);Database=Northwind;Trusted_Connection=yes];", AccessConn)

AccessCommand.ExecuteNonQuery();
AccessConn.Close();
  Permalink  
Comments
sinhasourabh at 26-Oct-12 1:52am
   
You are exporting only data from order table, not the entire table (schema + data) to mdb .
Kuthuparakkal at 26-Oct-12 7:19am
   
Read it fully before vomiting sheett
sinhasourabh at 26-Oct-12 7:30am
   
Execute this 'sheett' with a blank MDB and then tell how much this 'sheett' work.
Kuthuparakkal at 26-Oct-12 8:09am
   
You should understand that Select INTO would create new table. Learn to read and digest and use your brain
hayta6891 at 4-Jun-14 5:22am
   
It works fine for me to export mssql to mdb.
I just changed :
SELECT * INTO {New Table Name} FROM {Old Table Name} IN '' [ODBC; Driver={SQL Server}; Server=****; Database=****; UID=****; PWD=****];
Member 9877910 at 8-Jul-15 2:58am
   
I have tried a lot , I am unable to Fetch data every time getting error as : ODBC--connection to 'SQL Server(local)' failed.
Kuthuparakkal at 8-Jul-15 13:53pm
   
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestAccessDB
{
class Program
{
static void Main(string[] args)
{
Run();
}

private static void Run()
{
//Using JET.OLEDB :
System.Data.OleDb.OleDbConnection AccessConn = new
System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Data\Matrix\Info.accdb");

//Using ACE.OLEDB :
//System.Data.OleDb.OleDbConnection AccessConn = new
//System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Test Files\\db1.mdb")

AccessConn.Open();

//New table, using SELECT INTO
System.Data.OleDb.OleDbCommand AccessCommand = new System.Data.OleDb.OleDbCommand("SELECT * INTO [Accounts] FROM [Accounts] IN '' [ODBC;Driver={SQL Server};Server=(local);Database=Test;Trusted_Connection=yes];", AccessConn);

//Existing table, using INSERT INTO
//Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [ORDERS] SELECT * FROM [Orders] IN '' //[ODBC;Driver={SQL Server};Server=(local);Database=Northwind;Trusted_Connection=yes];", AccessConn)

AccessCommand.ExecuteNonQuery();
AccessConn.Close();
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 595
1 OriginalGriff 289
2 Andy Lanng 175
3 CPallini 162
4 ppolymorphe 126
0 OriginalGriff 8,958
1 Sergey Alexandrovich Kryukov 8,276
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,606


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 27 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100