ASP.NET 将 excel 导入 SQL
来源:互联网 发布:qemu运行arm linux 编辑:程序博客网 时间:2024/05/21 22:59
button的事件,凑合着看,需要先上传到服务器然后再读取
if (FileUpload1.PostedFile != null)
{
string str = FileUpload1.PostedFile.FileName;
int i = str.LastIndexOf("\\");
String filename=str.Substring(i+1);
FileUpload1.PostedFile.SaveAs(@Server.MapPath("xls") + filename);
Label1.Text = "文件名为" + filename;
string conn = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + Server.MapPath("xls") + "\\" + filename + ";Extended Properties=Excel 8.0";
OleDbConnection thisconnection = new OleDbConnection(conn);
thisconnection.Open();
string Sql = "select * from [Sheet1$]";
OleDbDataAdapter mycommand = new OleDbDataAdapter(Sql, thisconnection);
DataSet ds = new DataSet();
mycommand.Fill(ds, "[Sheet1$]");
thisconnection.Close();
string conn1 = System.Configuration.ConfigurationManager.ConnectionStrings["ZOPGConn"].ToString();
SqlConnection thisconnection1 = new SqlConnection(conn1);
thisconnection1.Open();
int count = ds.Tables["[Sheet1$]"].Rows.Count;
for (int j = 0; j < count; j++)
{
string id_1, id_2, id_3;
id_1 = ds.Tables["[Sheet1$]"].Rows[j]["id1"].ToString();
id_2 = ds.Tables["[Sheet1$]"].Rows[j]["id2"].ToString();
id_3 = ds.Tables["[Sheet1$]"].Rows[j]["id3"].ToString();
string excelsql = "insert into test(id1,id2,id3) values ('" + id_1 + "','" + id_2 + "','" + id_3 + "') ";
SqlCommand mycommand1 = new SqlCommand(excelsql, thisconnection1);
mycommand1.ExecuteNonQuery();
}
Response.Write("更新成功");
thisconnection1.Close();
}
- ASP.NET 将 excel 导入 SQL
- asp.net怎么将Excel表导入到sql数据库
- ASP.NET将EXCEL导入SQL SERVER数据库的代码
- ASP.NET将EXCEL导入SQL SERVER数据库的代码
- 转:Asp.Net将Excel数据导入Sql Server数据库
- ASP.NET将EXCEL导入SQL SERVER数据库的代码
- ASP.NET将EXCEL导入SQL+SERVER数据库的代码
- ASP.NET将EXCEL导入SQL SERVER数据库的代码
- 将Asp.net 数据导入Excel
- asp.net 如何将excel导入数据库
- ASP.NET Excel数据导入SQL Server
- asp.net中Excel导入SQL
- asp.net中Excel导入SQL
- ASP.NET导入Excel到数据库(SQL)
- ASP.NET导入Excel到数据库(SQL)
- asp.net Excel导入数据到sql
- ASP.NET导入Excel到数据库(SQL)
- ASP.NET导入Excel到数据库(SQL)
- JAVA..数组
- 数组
- C语言中比较两个浮点数是否相等的方法,fabs和abs
- C语言的那些秘密之---函数返回局部变量
- 财经郎眼。郎咸平--企业传承的忧与思
- ASP.NET 将 excel 导入 SQL
- 谈谈那些年我怀念的生活
- SQL Server 2005 彻底卸载、重装
- 第7周项目5友元模板类
- 读取用逗号分隔的文本文件
- ELF格式文件符号表全解析及readelf命令使用方法
- POJ 3678 Katu Puzzle
- 回归分析作业3
- loner_li JQuery 仿QQ相册(详细代码,包括css、js文件)