excel中导入到sql2005的表中 如果在客户端设置一个浏览控件 允许用户直接浏览本地机器的excel表格 然后上传。excel中的表头内容和数据库中表的内容相同,能否直接实现将excel中的内容直接导入到数据库中对应的表中。如何实现asp.net(C#)。谢谢各位帮忙,需要代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://dev.csdn.net/article/72/72658.shtm这些东西从网上直接就能够查找到 fileName = Request.MapPath(filePath); // string strConn ="Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Dir + "\\"+fileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1;\" string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"; string query = "SELECT * FROM [Sheet1$]"; OleDbCommand oleCommand = new OleDbCommand(query, new OleDbConnection(strConn)); OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand); DataSet myDataSet = new DataSet(); // 将 Excel 的[Sheet1]表内容填充到 DataSet 对象 try { oleAdapter.Fill(myDataSet, "[Sheet1$]"); // 数据绑定 this.dgExportProject.DataSource = myDataSet; this.dgExportProject.DataMember = "[Sheet1$]"; this.dgExportProject.DataBind(); this.dgExportProject.Visible = true; this.btnSave.Visible = true; } catch (Exception exx) { Response.Write(exx.Message); //Comm.Jscript.Alert("注意:请用默认的Sheet1$页名称!"); } finally { if (File.Exists(filePath)) { File.Delete(filePath); } } 如何注册上下文菜单 灰常急,Dataset中有相同数据,只显示一条 文件删除只能用绝对路径吗? 前台用JS调用后台代码 如何实现文件的下载 如何在.cs中给table赋值? 上传附件到文件服务器上,程序放在WEB服务器上,怎么解决??急啊 Crystal Report 在NTFS下出现登录失败问题 AJAX的问题 谁帮我看看,这段asp.net(vb)的代码,那里错误了? 关于.pwa文件 学习.NET中的困惑
// string strConn ="Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + Dir + "\\"+fileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1;\"
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
string query = "SELECT * FROM [Sheet1$]";
OleDbCommand oleCommand = new OleDbCommand(query, new OleDbConnection(strConn));
OleDbDataAdapter oleAdapter = new OleDbDataAdapter(oleCommand);
DataSet myDataSet = new DataSet(); // 将 Excel 的[Sheet1]表内容填充到 DataSet 对象
try
{
oleAdapter.Fill(myDataSet, "[Sheet1$]");
// 数据绑定
this.dgExportProject.DataSource = myDataSet;
this.dgExportProject.DataMember = "[Sheet1$]";
this.dgExportProject.DataBind(); this.dgExportProject.Visible = true;
this.btnSave.Visible = true;
}
catch (Exception exx)
{
Response.Write(exx.Message);
//Comm.Jscript.Alert("注意:请用默认的Sheet1$页名称!");
}
finally
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
}