c# - 从 RDB 文件中读取数据
问题描述
我得到了一个 RDB 扩展名的文件。我需要从此文件中获取数据以将数据放入 DataTable 中。但我不知道如何从 RDB 文件中读取数据。我没有在互联网上找到信息。
请帮我。
祝你有美好的一天。
解决方案
我将数据作为字符串放入 DataTable 中。我没有包含原始代码中的任何格式。
public class Lecture
{
public DataTable Lecture_RDB(string databaseName)
{
//Déclarartions des variables
double mem_time, valeur_init;
int ititre, k, l, nbligne;
string entete = ";";
string[] titre = new string[9];
List<string> ligne = new List<string>();
string ecriture = "";
string indicetag = "";
string destination = "";
string mem_titre = "";
DataTable dt = new DataTable();
dt.Columns.Add("Col A", typeof(string));
dt.Columns.Add("Col B", typeof(string));
dt.Columns.Add("Col C", typeof(string));
dt.Columns.Add("Col D", typeof(string));
//Déclarations base de données
SQLite.SQLiteConnection SQLconnect = new SQLite.SQLiteConnection();
SQLiteCommand SQLcommand;
SQLiteDataReader SQLreader;
try
{
//Connexion au fichier RDB
SQLconnect.ConnectionString = "Data Source=" + databaseName + ";";
SQLconnect.Open();
//Creation Requete pour lecture en-tete
SQLcommand = SQLconnect.CreateCommand;
SQLcommand.CommandText = "SELECT * FROM logdata";
//Execution requete
SQLreader = SQLcommand.ExecuteReader();
while (SQLreader.Read())
{
string[] row = SQLreader.Cast<object[]>().Select(x => x.ToString()).ToArray();
dt.Rows.Add(row);
}
}
catch(Exception ex)
{
//Si erreur pendant la lecture du fichier message
Console.WriteLine("Error file reading : {0}.{1} Error", databaseName, ex.Message);
}
return dt;
}
}
推荐阅读
- javascript - 用于自动分配变量的 Javascript DRY 方法
- javascript - 为什么 flatMap 不删除空数组?
- postgresql - 在 ecpg 中重新分配的好顺序
- express - JSON 有效负载中的 URL 导致 CORS 问题
- c++ - ReadFile 函数无法正确读取文件 - Win32 API
- python - 我没有收到附件
- database - 查找和替换数据库中的 URL,而不在 URL 末尾添加斜杠
- php - 在结帐页面(woocommerce)中将自定义字段插入数据库中的自定义表
- vba - 用于在表格中添加列表格式的命令按钮和文本框
- php - 如何使用 powershell 更改任务计划程序中的安全选项