Пример #1
0
 public void Add(SimpleFile sf)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
         using (SqlCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText = "INSERT INTO Files (Name, FileName) VALUES " +
                               "(@name, @fileName)";
             cmd.Parameters.AddWithValue("@name", sf.Name);
             cmd.Parameters.AddWithValue("@fileName", sf.FileName);
             connection.Open();
             cmd.ExecuteNonQuery();
         }
 }
Пример #2
0
 public IEnumerable <SimpleFile> GetAll()
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
         using (SqlCommand cmd = connection.CreateCommand())
         {
             cmd.CommandText = "SELECT * FROM Files";
             connection.Open();
             List <SimpleFile> files  = new List <SimpleFile>();
             SqlDataReader     reader = cmd.ExecuteReader();
             while (reader.Read())
             {
                 SimpleFile sf = new SimpleFile
                 {
                     Id       = (int)reader["Id"],
                     FileName = (string)reader["FileName"],
                     Name     = (string)reader["Name"]
                 };
                 files.Add(sf);
             }
             return(files);
         }
 }