Hasibul Kamel

Hasibul Kamel

  • NA
  • 44
  • 4.3k

compare file in database

Aug 17 2020 11:05 PM
Hi, I have a system that can save and read CSV files and store the records in the database.

The problem is how to compare if the file already save in database. If there is a new file, the system will save the file name and last write time.
 
foreach (FileInfo file in filess)
                {
                    var lf = "insert into listfile(filename,lastWriteTime)values(@filename,@lastWriteTime)";
                    var cmd = new NpgsqlCommand(lf, conn);

                    DateTime lastWriteTime = file.LastWriteTime;

                    cmd.Parameters.AddWithValue("filename", Convert.ToString(file));
                    string filename = cmd.Parameters["@filename"].Value.ToString();
                    Console.WriteLine("Record inserted successfully. filename = " + file);

                    cmd.Parameters.AddWithValue("file last write time", Convert.ToDateTime(lastWriteTime));
                    string lastwritetime = cmd.Parameters["@lastWriteTime"].Value.ToString();
                    Console.WriteLine("Record inserted successfully. file last write time = " + lastWriteTime);

                    Console.WriteLine("File list : " + file);
                    Console.WriteLine("Time last Edit : " + lastWriteTime);

                    if (file.Exists)
                    {
                        var sel = "select * from listfile";
                        var cmd1 = new NpgsqlCommand(sel, conn);
                    }
                    else
                    {

                    }
                }
 
I'm stuck at here, help me please

Answers (6)