> Asp.net C# Code
**
I have one excel File 2013 Version Create And Excel File Data Insert Sql Server 2012 Table So Error
("External table is not in the expected format. in asp.net")
Excle File Image
Database Table Image
My Above Two Table And Colum
So iahve Trasfer Data Excel 2013 Version Filedata in sql Server 2012 Table .
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
External table is not in the expected format.
birju gohelPosted Feb 13, 2015, 3:01 AM
=========================================
public static string path = @"C:\Users\asp\Desktop\ColoreCode.xlsx";
public static string excelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
====================================================
Click Event
========================================================
protected void Button1_Click(object sender, EventArgs e)
{
//string CurrentFilePath = Path.GetFullPath(FileUpload1.PostedFile.FileName);
//InsertExcelRecords(CurrentFilePath);
//connection();
if (!FileUpload1.HasFile)
{
try
{
//string path = string.Concat(Server.MapPath("~/Image/ColoreCode.xlsx"));//+ FileUpload1.FileName));
//FileUpload1.SaveAs(path);
// Connection String to Excel Workbook
// string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
// string excelconnectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";"+"Extended Properties="Excel 12.0;HDR=Yes";
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = excelConnectionString;
OleDbCommand command = new OleDbCommand("select * from [Sheet5$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
DbDataReader dr = command.ExecuteReader();
// SQL Server Connection String
string sqlConnectionString = @"Data Source=ASP4;Initial Catalog=Cricketers;User ID=xxxxxxx;Password=xxxxxxxxxx";
// Bulk Copy to SQL Server
SqlBulkCopy bulkInsert = new SqlBulkCopy(sqlConnectionString);
bulkInsert.DestinationTableName = "ColorMaster";
bulkInsert.WriteToServer(dr);
Label1.Text = "Ho Gaya";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
}
}
birju gohelPosted Feb 13, 2015, 2:58 AM