对于.Net 4.0和.net Framework Client Profile 4.0,Oledb的行为有所不同

时间:2013-05-15 16:33:40

标签: .net-4.0 oledb

案例1: 在.Net Framework客户端配置文件中使用Oledb读取excel时,Oledb会读取excel中的数据,忽略excel中给出的格式

示例:1.98782637是实际值,但格式化后显示为1.99。 当我从我的代码中读取时,读取的值是1.98782637。

案例2: 在.Net Framework中使用Oledb读取excel时,Oledb会在格式化后读取excel中可用的数据

示例:1.98782637是实际值,但格式化后显示为1.99。 当我从我的代码中读取时,读取的值是1.99。

以下是我用于这两种情况的代码。

        DataSet dsoutlier = null;
        OleDbDataAdapter oledbAdapterOutlier = null;
        OleDbConnection oledbConnOutlier = new OleDbConnection();

        string fileName = "C:\\Sample.xlsx";           
       oledbConnOutlier.ConnectionString= "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + fileName + ";Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=0;\'"; 

        if (oledbConnOutlier.State == ConnectionState.Closed)
            oledbConnOutlier.Open();
        oledbAdapterOutlier = new OleDbDataAdapter("select F1,F9 from [Sheet1$] where F1 is not null", oledbConnOutlier);
        dsoutlier = new DataSet();

        try
        {
            oledbAdapterOutlier.Fill(dsoutlier);
            int counter = 0;
            foreach (var item in dsoutlier.Tables[0].Rows)
            {
                Console.Write(dsoutlier.Tables[0].Rows[counter][0]+"  ");
                Console.WriteLine(dsoutlier.Tables[0].Rows[counter++][1]);


            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
            oledbConnOutlier.Close();
        }

是否有办法在两种情况下都包含和忽略格式化?

0 个答案:

没有答案
相关问题