首页 新闻 会员 周边 捐助

Execle

0
[待解决问题]

怎么做一个Execle导入数据库,能不能给个具体点的例子,并说一下具体注意事项

杀  手的主页 杀 手 | 菜鸟二级 | 园豆:213
提问于:2011-05-06 09:10
< >
分享
所有回答(3)
0
邀月 | 园豆:25475 (高人七级) | 2011-05-06 12:26
0

你是用c#代码写吧!

如果是的话就要 检查表头,数据格式,还有就是防止中间有空行等

小小刀 | 园豆:1991 (小虾三级) | 2011-05-06 16:11
0

 MenuHelper.ExceclType exceclType;
            string path = string.Empty;

            string excelConnect = string.Empty;

            if (Global.ExcelVersion == "2007")
            {
                exceclType = MenuHelper.ExceclType.Excecl2007;
            }
            else
            {
                exceclType = MenuHelper.ExceclType.Excecl2003;
            }
            if (exceclType == MenuHelper.ExceclType.Excecl2003)
            {
                path = string.Format(@"{0}\{1}.{2}", Global.ExcelToPath, tableName, "xls");
                excelConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + "Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
            }
            else if (exceclType == MenuHelper.ExceclType.Excecl2007)
            {
                path = string.Format(@"{0}\{1}.{2}", Global.ExcelToPath, tableName, "xlsx");
                excelConnect = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + path + ";Extended Properties='Excel 12.0; HDR=YES; IMEX=1'";

            }
            string excelCom = string.Empty;
            OleDbConnection excelConn = new OleDbConnection(excelConnect);
            excelConn.Open();
            DataTable excelDT = null;
            excelDT = excelConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            OleDbDataAdapter oad = new OleDbDataAdapter("select * from [" + excelDT.Rows[0]["TABLE_NAME"].ToString() + "]", excelConn);
            DataSet ds = new DataSet();
            oad.Fill(ds);
            return ds.Tables[0];

辛巴 | 园豆:622 (小虾三级) | 2011-05-10 13:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册