asp.net 将excel表的内容插入到数据库
在c#里,
我做的是底层的插入。
实体层,数据层,业务层已经有表的属性了,
要实现将excel表里的内容插入到已有的数据库的某一表中。
比如excel表里有属性A,B,C,D,E
数据库里的表的名字是excelTable
插入的时候是以行的形式插入的,
求实现此操作的全部代码~~
谢谢!!!
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel = "select * from [sheet1$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
ds = new DataSet();
myCommand.Fill(ds, "table1");
return ds;
}
把excel数据读到DataSet中然后再插入到数据库就可以了
private void button1_Click(object sender, System.EventArgs e)
{
//选择文件
ofdSelec
相关问答:
asp下面,当要根据不同的权限显示一些功能按钮的话会写成
<%
if 权限=1 then
%>
<input type="submit" name="Submit" value="提交" />
<%
end i ......
如题!
FileUpload1.PostedFile.FileName
我这样写了 但是还是获得的是一个文件的名称,FileUpload1.FileName 这个也是一样!
FileUpload1.PostedFile.FileName
IE 问题
工具-internet选项-安全- ......
前段时间碰到一道面试题如下:
test.aspx页面有如下代码:
Response.Write(Test.GetDate());
Test类如下:
public class Test
{
static string dt="";
public static s ......