通过ASP.NET使excel导入到数据库,请高手指点
我要实现的功能是,单击一个BUTTON弹出选择路径,之后在路径下选择excel文件或者TXTX文本文件,之后导入到数据库的一个表里面。请高手指点给出代码参考。
------解决方案--------------------ds = new DataSet();
ds = FEGCRM.Access.OrderDA.XSGetData(strquery, currentCorporatioCode);
DataTable dt = ds.Tables[ "Product "];
dt.Columns[ "DocNum "].ColumnName = "SAP订单编号 ";
dt.Columns[ "LineNum "].ColumnName = "明细编号 ";
dt.Columns[ "SN "].ColumnName = "排程编号 ";
dt.Columns[ "CardName "].ColumnName = "客户名称 ";
dt.Columns[ "ItemCode "].ColumnName = "生产名称 ";
dt.Columns[ "U_dj "].ColumnName = "等级 ";
dt.Columns[ "StockNumber "].ColumnName = "采购单号码 ";
dt.Columns[ "S_Product_Name "].ColumnName = "产品名称(SAP) ";
dt.Columns[ "S_Remark "].ColumnName = "公司备注 ";
dt.Columns[ "S_Grade_S "].ColumnName = "特代 ";
dt.Columns[ "S_One_zld "].ColumnName = "支重 ";
dt.Columns[ "S_SumQuantitys "].ColumnName = "支数 ";
dt.Columns[ "S_Stock "].ColumnName = "实际库存 ";
dt.Columns[ "Operative "].ColumnName = "生产线顺序 ";
dt.Columns[ "S_LineNo "].ColumnName = "线别 ";
dt.Columns[ "S_Product_Quantity "].ColumnName = "生产数量 ";
dt.Columns[ "S_Prodict_Date "].ColumnName = "生产日期 ";
dt.Columns[ "S_PCompDete_Date "].ColumnName = "生产完成日期 ";
dt.Columns[ "S_DC "].ColumnName = "预定发货 ";
dt.Columns[ "InceptTime "].ColumnName = "接单日期 ";
dt.Columns[ "S_FactoryRemark "].ColumnName = "工厂备注 ";
dt.Columns[ "S_PA_Quantity "].ColumnName = "生产完成数量 ";
dt.Columns[ "Date_Prognosis "].ColumnName = "预定发货日期 ";
dt.Columns[ "SumQuantity "].ColumnName = "已完成总数量 ";
StringWriter sw = new StringWriter();
GridView dv = new GridView();
dv.DataSource = dt;
dv.DataBind();
dv.AllowPaging = false;
Response.ClearContent();
Response.Charset = "GB2312 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=MyExcelFile.xls ");
// 如果设置为 GetEncoding( "GB2312 ");导出的文件将会出现乱码!!!
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/excel ";
#region
//Response.ClearContent();
//Response.AddHeader( "content-disposition ", "attachment; filename=MyExcelFile.xls ");
//Response.ContentType = "application/excel ";
//StringWriter sw = new StringWriter();
#endregion
HtmlTextWriter htw = new HtmlTextWriter(sw);
dv.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();