本文介绍了如何防止加载SQL的浮点数excel数据被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用SQL在我的C#软件中从Excel加载浮点数据时,数据最终会被截断。



例如,我结束了0,054034最多0,054。



我尝试过:



相关我的部分代码是:



 DataTable part8 = new DataTable(); 
part8 = loadData(路径,SELECT * FROM [Gaszähler$ X13:Y]);
Console.WriteLine(part8.Rows [10] [1]);

private DataTable loadData(String path,String command)
{
String filepath = path;
String db_command = command;

OleDbDataAdapter adapter = fetch(filepath,db_command);
DataSet set = new DataSet();
DataTable returntable = new DataTable();
adapter.Fill(set,table1);
returntable = set.Tables [table1];

返回可退回;
}

public OleDbDataAdapter fetch(string filepath,string com)
{
OleDbConnection conn = new OleDbConnection(); // Die Verbindung
string ConStr = // Der Connectionstring
@Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ filepath
+ @; Extended Properties = Excel 8.0; HDR =是; IMEX = 1; ImportMixedTypes = Text; TypeGuessRows = 0;

conn.ConnectionString = ConStr; // Der Connectionstring wird gesetzt

OleDbCommand command = new OleDbCommand // Das OleDb Kommando

com,conn
);
OleDbDataAdapter myAdapter = new OleDbDataAdapter(command); // Ein Adapter

返回myAdapter;
}
解决方案



When I load floating point data from Excel in my C# software using SQL the data ends up being truncated.

For example, instead of 0,054034 I end up with 0,054.

What I have tried:

The relevant part of my code is:

DataTable part8 = new DataTable();
part8 = loadData(path, "SELECT * FROM [Gaszähler$X13:Y]");
Console.WriteLine(part8.Rows[10][1]);

private DataTable loadData(String path, String command)
{
    String filepath = path;
    String db_command = command;

    OleDbDataAdapter adapter = fetch(filepath, db_command);
    DataSet set = new DataSet();
    DataTable returntable = new DataTable();
    adapter.Fill(set, "table1");
    returntable = set.Tables["table1"];

    return returntable;
}

public OleDbDataAdapter fetch(string filepath, string com)
{
    OleDbConnection conn = new OleDbConnection(); // Die Verbindung
    string ConStr = // Der Connectionstring
         @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + filepath
        + @";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";

    conn.ConnectionString = ConStr; //Der Connectionstring wird gesetzt

    OleDbCommand command = new OleDbCommand // Das OleDb Kommando
        (
            com, conn
        );
    OleDbDataAdapter myAdapter = new OleDbDataAdapter(command); // Ein Adapter

    return myAdapter;
}
解决方案



这篇关于如何防止加载SQL的浮点数excel数据被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:35