我用C#把Excel文档里的数据导入到SQL数据库中,Excel中有一列有些是字母加数字,有些全是数字,字母加数字的能正常显示,全数字的导进去就是空的了,如果加一字母就又正常了,我把Excel文档设置成常规、文本都不行

解决方案 »

  1.   

    我不要改Excel 只改C#程序啊,别的文档一格里全是数字也能正常导啊
      

  2.   

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" 
    "HDR=Yes;" indicates that the first row contains columnnames, not data
    "IMEX=1;" tells the driver to always read "intermixed" data columns as text
    TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.IMEX=1:把所有单元格数据当成字符串来读.
      

  3.   

    还是不行啊。我导入Excel的类如下,帮我分析一下。
    public DataSet ExcelToDS(string Path)
    {
    string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + Path + ";" +
    "Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;";
    OleDbConnection conn = new OleDbConnection(strConn); 
    conn.Open(); 
    string strExcelPSID = ""; 
    OleDbDataAdapter myCommand = null; 
    DataSet ds = null; 
    strExcelPSID="select * from [Sheet1$]"; 
    myCommand = new OleDbDataAdapter(strExcelPSID, strConn); 
    ds = new DataSet(); 
    myCommand.Fill(ds,"table1"); 
    conn.Close();
    return ds;
    }
    而且导入Excel后,这个文件就不能打开了,我要把aspnet_wp进程关掉才能打开(XP系统)。我不是把连接关闭了吗?怎么还是不能释放?