Search code examples
c#sqlreadfile

Read Data from a RDB file


I got a file that is in RDB extension. I need to get the data from this file to put data in a DataTable. But i don't know how to read data from RDB files. I didn't find informations on internet.

Please help me.

Have a great day.


Solution

  • I put data into a DataTable as strings. I didn't include any formatting that was in the original code.

    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;
        }
    }