Click here to Skip to main content
15,921,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to import record's from datagridview to ms access. Can somebody provide me a small samble project?
Posted
Updated 15-Jan-14 6:14am
v3

Try:
C#
string strConnect = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Temp\myAccessDatabase.accdb";
using (OleDbConnection con = new OleDbConnection(strConnect))
    {
    con.Open();
    using (OleDbCommand cmd = new OleDbCommand("SELECT * FROM MyTable", con))
        {
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        myDataGridView.DataSource = dt;
        }
    }
 
Share this answer
 
Comments
Member 10010674 16-Jan-14 10:15am    
THIS WHERE DOING ON FORM LOAD EVAND
Member 10010674 16-Jan-14 10:20am    
I NEED WRITE DATAGRID VIEW TO ACCSESS ..I HAVE 3 TEXT BOX ON FRM
THAT FIST TEXT TO DATAGRID, THAT CODE I DO OK,BUT DATA GRID TO ACCSESS NOT GET PLEASE HELP ME
OriginalGriff 16-Jan-14 11:35am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
meerDcoder 28-Sep-20 5:47am    
I have a DataGrid and this is not working. My dataTable is not populating the DataGrid. Thanks
OriginalGriff 28-Sep-20 5:54am    
So ... six years later you post "it don't work" and assume I will know exactly why your code that I have never seen is doing wrong? :sigh:
try like this,
if any issues post a comment.
i assume you will get issue on the choosing the correct provider in connection string..as i don't know which version of excel u r using...

C#
private void button1_Click(object sender, EventArgs e)
       {
           string connString =
               "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\\excelFileName.accdb";

           DataTable dataTableRes = new DataTable();

           using (OleDbConnection conn = new OleDbConnection(connString))
           {
               OleDbCommand cmd = new OleDbCommand("SELECT * FROM SheetName", conn);

               conn.Open();

               OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);

               adapter.Fill(dataTableRes);
           }

           dataGridView1.DataSource = dataTableRes;
       }
 
Share this answer
 
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900