asp.net中excel导入ms sql数据库
2008-06-05 15:39
239 查看
protected void change_ServerClick(object sender, EventArgs e) { string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + filedata.Value +";Extended Properties=Excel 8.0"; OleDbConnection cnnxls = new OleDbConnection (mystring); OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [Sheet1$]",cnnxls); DataSet myDs =new DataSet(); myDa.Fill(myDs); if(myDs.Tables[0].Rows.Count > 0) { string strSql = ""; string CnnString = "Provider=SQLOLEDB;database=DRUGS_CMS;server=(local);uid=sa;pwd=sa"; OleDbConnection conn =new OleDbConnection(CnnString); conn.Open (); OleDbCommand myCmd =null; for(int i=0; i<myDs.Tables[0].Rows.Count; i++) { strSql = "insert into CMS_DRUS values ('"; strSql += myDs.Tables[0].Rows[i].ItemArray[0].ToString() + "', '"; strSql += myDs.Tables[0].Rows[i].ItemArray[1].ToString() + "', '"; strSql += myDs.Tables[0].Rows[i].ItemArray[2].ToString() + "', '"; strSql += myDs.Tables[0].Rows[i].ItemArray[3].ToString() + "', '"; strSql += myDs.Tables[0].Rows[i].ItemArray[4].ToString() + "', '"; strSql += int.Parse(myDs.Tables[0].Rows[i].ItemArray[5].ToString()) + "', '"; strSql += Decimal.Parse(myDs.Tables[0].Rows[i].ItemArray[6].ToString()) + "', '"; strSql += myDs.Tables[0].Rows[i].ItemArray[7].ToString() + "', '"; strSql += DateTime.Parse(myDs.Tables[0].Rows[i].ItemArray[8].ToString()) + "', '"; strSql += int.Parse(myDs.Tables[0].Rows[i].ItemArray[9].ToString()) + "', '"; strSql += Decimal.Parse(myDs.Tables[0].Rows[i].ItemArray[10].ToString()) + "', '"; strSql += myDs.Tables[0].Rows[i].ItemArray[11].ToString() + "', '"; strSql += DateTime.Parse(myDs.Tables[0].Rows[i].ItemArray[12].ToString()) + "', '"; strSql += int.Parse(myDs.Tables[0].Rows[i].ItemArray[13].ToString()) + "', '"; strSql += DateTime.Parse(myDs.Tables[0].Rows[i].ItemArray[14].ToString()) + "', '"; strSql += int.Parse(myDs.Tables[0].Rows[i].ItemArray[15].ToString()) + "')"; try { myCmd=new OleDbCommand(strSql,conn); myCmd.ExecuteNonQuery(); Response.Write("<script language=javascript>alert('数据导入成功.');</script>"); } catch(Exception m_Error) { Response.Write(m_Error.Message.ToString()); } } conn.Close();}
相关文章推荐
- asp.net中excel导入ms sql数据库
- Asp.NET MVC 导入Excel数据教程 手把手教你系列!!!
- ExcelHelper(Excel和C#、asp.net导入导出,通用类)(五)
- [导入]Asp.net 2.0 GridView数据导出Excel文件(示例代码下载)
- ASP.NET Aries 高级开发教程:Excel导入之单表配置(上)
- ASP.NET中如何把EXCEL中数据导入到SQL SERVER
- asp.net导入excel转为datatable
- asp.net access导入Excel
- Asp.Net页面导入和导出到EXCEL
- ASP.NET中数据库数据导入Excel并打印
- asp.net Excel导入和导出
- [导入]ASP.NET 2.0中直接将Access数据库导入到Excel文件中
- asp.net实现将Excel中多个sheet数据导入到SQLSERVER中的方法
- ASP.NET excel 导入数据库 出现 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序问题的解决
- C#数据库数据导入导出系列之一 ASP.NET Excel导入Sql Server数据库
- ASP.NET MVC NPOI导入导出Excel
- ASP.NET中数据库数据导入Excel并打印
- asp.net 将数据导入到excel中 出现 “object”未包含“get_Range”的定义
- Asp.net中Excel数据导入到SQL Server
- sql sever2005中批量导入excel表格数据(Asp.net C#)