我遇到了一个很怪的问题,用excel导入到oracle中,
 public DataSet ExceltoDs(string FilePath)
        {
            string strCon;
            strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + "; Extended Properties=Excel 8.0;";
            OleDbConnection olecon = new OleDbConnection(strCon);
            OleDbDataAdapter myda = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", olecon);
            DataSet myds = new DataSet();
            myda.Fill(myds);
            File.Delete(FilePath);
            return myds;
        }//先导入到dataset中
   private void ExcelDaru(string FilePath)
        {
            Model.SYSDB.BINFO_DEPARTMENT model_binfo_department = new Model.SYSDB.BINFO_DEPARTMENT();
            DataSet ds_binfo_department = ExceltoDs(FilePath);         //将Excel中的数据放入ds
            foreach (DataRow dr in ds_binfo_department.Tables[0].Rows)
            {
                BLL.SYSDB.BINFO_DEPARTMENT bll_binfo_department = new BLL.SYSDB.BINFO_DEPARTMENT();
                model_binfo_department.depname = dr[1].ToString();
                model_binfo_department.depcode = dr[0].ToString();
                model_binfo_department.iseffect = '1';
                if (model_binfo_department.depcode != "" & model_binfo_department.depname != "")//2008.06.20
                {
                    if (!bll_binfo_department.Add(model_binfo_department))
                    {
                        MsgBox msg = new MsgBox();
                        msg.Show(this, "数据有误,请检查数据!");
                    }
                }
            }
      }
depcode depname
123 A厂
234 B厂
ww C厂
导入数据如上,可是我发现如果depcode全是数字或者全是字符,顺利导入,但是如果depcode即有数字又有字符,dataset中只有数字,没有字符,也有是只能导入前两个,很诡异,不知道是什么原因,请各个大虾帮帮忙!非常感谢!

解决方案 »

  1.   

    为啥没人理我,这个问题很诡异,不知道为什么会这样?
    我把数字前加单引号,OK!
    难道只能导全部是数字或者全部是字符?我调试了一下发现DataSet ds_binfo_department后面多了好多空行,怎么会这样,哪们高手帮忙解决一下!谢谢了
      

  2.   

    使用这种方法读取数据时,确实会出现各种各样不可预料的问题。
    你可下载一个专门用于读取excel的控件,Aspose.Cells,很好用,不会再出现你所说的问题。
      

  3.   

    可能是execle单元格,格式的问题,execle右键单元格->格式,设置一下单元格数字的
    为数字,字符为字符