首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从RDB文件中读取数据

从RDB文件中读取数据
EN

Stack Overflow用户
提问于 2020-11-16 13:20:17
回答 1查看 1.2K关注 0票数 0

我有一个在RDB扩展名中的文件。我需要从这个文件中获取数据,以便将数据放入DataTable中。但我不知道如何从RDB文件中读取数据。我在网上没有发现任何信息。

请帮帮我。

祝你今天过得愉快。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-17 16:05:33

我将数据作为字符串放入DataTable中。我没有在原始代码中包含任何格式。

代码语言:javascript
复制
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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64858785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档