c# - 如何防止使用 SQL 加载的浮点 Excel 数据被截断
问题描述
当我使用 SQL 在我的 C# 软件中从 Excel 加载浮点数据时,数据最终被截断。
例如,我最终得到的不是 0,054034,而是 0,054。
我的代码的相关部分是:
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;
}
解决方案
推荐阅读
- flutter - 如何获取 PWA 支持的布尔值 Flutter web
- javascript - MSAL.js 库中的自定义错误日志记录不起作用
- java - Selenium java,模拟 json 对扩展的响应
- c# - 一行程序上的两个 DataGrids 冻结 WPF
- http - 应该使用 Post 或 Put - 如果存在要更新的对象,否则要创建新对象?
- c# - EF Core 上下文不包含添加实体的更改
- postgresql - postgres_1 | ls: 无法访问'/docker-entrypoint-initdb.d/': 不允许操作
- metafor - 使用 metafor 计算效果大小(使用“SMD”):插入组差异的标准差而不是组特定的 SD?
- python - 如何获取 Opennebula XML-RPC api 所需的参数
- c# - C# 8+ 可空引用检查:静态分析能否确定该字段或该字段为非空?