首页 > 解决方案 > 从 RDB 文件中读取数据

问题描述

我得到了一个 RDB 扩展名的文件。我需要从此文件中获取数据以将数据放入 DataTable 中。但我不知道如何从 RDB 文件中读取数据。我没有在互联网上找到信息。

请帮我。

祝你有美好的一天。

标签: c#sqlreadfile

解决方案


我将数据作为字符串放入 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;
    }
}

推荐阅读