how to export excel to Msaccess

Posted by Jayakumars under ASP.NET on 10/25/2011 | Points: 10 | Views : 1178 | Status : [Member] [MVP] | Replies : 1
hi

I have 1 excel sheet in 2 sheets have now i need when i click export
button read every column to export msaccess every records same excel
format how will do this below attach my excel sheet.

Mark as Answer if its helpful to you


Responses

Posted by: Abdulhaknet on: 10/25/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Friend ,

Please try the sample code for TRansfer data from Excel to Access.
--------------------------------------------------------------------------------------------------------------
string Access = Server.MapPath("App_Data/contacts.mdb");
string Excel = Server.MapPath("App_Data/Book1.xls");
string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Excel +";Extended Properties=Excel 8.0;";
using (OleDbConnection conn = new OleDbConnection(connect))
{
using (OleDbCommand cmd = new OleDbCommand())
{
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO [MS Access;Database=" + Access + "].[Persons] SELECT * FROM [Sheet1$]";
conn.Open();
cmd.ExecuteNonQuery();
}
}

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response