Example #1
0
 public FileD SelectById(int file_id)
 {
     lock (locker)
     {
         using (MySqlCommand sqlCommand = new MySqlCommand("SELECT * FROM files WHERE file_id=@file_id", connection))
         {
             sqlCommand.Parameters.AddWithValue("@file_id", file_id);
             using (MySqlDataReader reader = sqlCommand.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     FileD file = new FileD();
                     file.file_id        = reader.GetInt32(0);
                     file.file_path      = reader.IsDBNull(1) ? "" : reader.GetString(1);
                     file.file_name      = reader.GetString(2);
                     file.file_type      = reader.IsDBNull(3) ? "" : reader.GetString(3);
                     file.file_extension = reader.IsDBNull(4) ? "" : reader.GetString(4);
                     return(file);
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
     }
 }
 public FileD SelectById(int file_id)
 {
     lock (locker)
     {
         using (MySqlCommand sqlCommand = new MySqlCommand(selectbyid, connection))
         {
             using (MySqlDataReader reader = sqlCommand.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     FileD file = new FileD();
                     file.file_id        = reader.GetInt32(0);
                     file.file_path      = reader.IsDBNull(1) ? "" : reader.GetString(1);
                     file.file_name      = reader.GetString(2);
                     file.file_type      = reader.IsDBNull(3) ? "" : reader.GetString(3);
                     file.file_extension = reader.IsDBNull(4) ? "" : reader.GetString(4);
                     return(file);
                 }
                 else
                 {
                     return(null);
                 }
             }
         }
     }
 }
Example #3
0
 public FileD AddFile(FileD file)
 {
     if (file != null)
     {
         lock (locker)
         {
             using (MySqlCommand sqlCommand = new MySqlCommand(insert, connection))
             {
                 sqlCommand.Parameters.AddWithValue("@file_path", file.file_path);
                 sqlCommand.Parameters.AddWithValue("@file_name", file.file_name);
                 sqlCommand.Parameters.AddWithValue("@file_type", file.file_type);
                 sqlCommand.Parameters.AddWithValue("@file_extension", file.file_extension);
                 sqlCommand.ExecuteNonQuery();
                 file.file_id = (int)sqlCommand.LastInsertedId;
                 sqlCommand.Dispose();
             }
         }
         return(file);
     }
     return(null);
 }