string path = string.Concat(Server.MapPath("~/TempFiles/"), FileUpload1.FileName);
//Save File as Temp then you can delete it if you want
FileUpload1.SaveAs(path);
string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 8.0", path);
// Create Connection to Excel Workbook
using (OleDbConnection connection =
new OleDbConnection(excelConnectionString))
{
OleDbCommand command = new OleDbCommand
("Select * FROM [Sheet1$]", connection);
connection.Open();
// Create DbDataReader to Data Worksheet
using (DbDataReader dr = command.ExecuteReader())
{
// SQL Server Connection String
string sqlConnectionString = @conn;
// Bulk Copy to SQL Server
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(sqlConnectionString))
{
bulkCopy.DestinationTableName ="Table1";
bulkCopy.WriteToServer(dr);
Label1.Text = "The Client data has been exported successfully from Excel to SQL";
}
}
}
我试图从Excel到SQL Server导入数据,它工作得很好,直到我没有通过的日期,但现在我想传递的日期到SQL Server提供由于数据类型不匹配而导致错误。导入数据从Excel到SQL Server 2008#2
任何人有逻辑或请建议我,我能做些什么来..
我怎么能转换它,因为我导入数据在BU lk .. 是否有任何东西可以导入到数据表中,然后导入到sql服务器,以便我们可以检查数据表中的每个数据并将其转换为 – user2919184
检查我的更新答案。 – Adil
你好,因为我是新来的asp我不知道,但我检查了..我使用datareader nd我正在执行datareader插入我的价值,如果我写入数据表,然后如何执行它的数据值插入我的数据? ? n thanx为您的回复 – user2919184