一个EXCEL进程的问题
最近我做一个管理系统,要用到excel的上传功能。要在上传后删除excel文件,我是要做的:
我一个excel文件里面有2个sheet 都要上传
按钮事件我是主要写的:
protected void BtnUpload_Click(object sender, EventArgs e)
{
string fileName = this.FileUpload1.FileName;
string UploadFileName = Request.MapPath(Request.ApplicationPath + "\\ " + System.IO.Path.GetFileName(fileName));
A();
GC.Collect();
System.IO.File.Delete(UploadFileName);
B();
GC.Collect();
System.IO.File.Delete(UploadFileName);
System.GC.Collect();
}
protected voidA()
{
string fileName = this.FileUpload1.FileName;
string UploadFileName = Request.MapPath(Request.ApplicationPath + "\\ " + System.IO.Path.GetFileName(fileName));
this.FileUpload1.PostedFile.SaveAs(UploadFileName);
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + UploadFileName + ";Extended Properties=Excel 8.0 ";
string query = "SELECT * FROM [提取物生产信息$] ";
................................
try
{
OleDbConnection oleconn = new OleDbConnection(ConnStr);
oleconn.Open();
OleDbCommand oleCommand = new OleDbCommand(query, oleconn);
OleDbDataReader rdr;
rdr = oleCommand.ExecuteReader();
if (rdr.Read())//多读一行 可在EXCEL里面加一行
{
SqlConnection conn = new SqlConnection
(ConfigurationManager.ConnectionStrings[ "sqlConnString "