Esempio n. 1
0
        public static int Insert(Obor obor, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_INSERT);

            PrepareCommand(command, obor);
            int ret = db.ExecuteNonQuery(command);

            if (pDb == null)
            {
                db.Close();
            }

            return(ret);
        }
Esempio n. 2
0
        public static int Update(Obor obor)
        {
            var db = new Database();

            db.Connect();

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, obor);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
Esempio n. 3
0
        private static Collection <Obor> Read(SqlDataReader reader, bool complete)
        {
            Collection <Obor> obory = new Collection <Obor>();

            while (reader.Read())
            {
                Obor obor = new Obor();
                int  i    = -1;
                obor.IdObor = reader.GetInt32(++i);

                if (complete)
                {
                    obor.Nazev = reader.GetString(++i);
                    obor.Popis = reader.GetString(++i);
                }

                obory.Add(obor);
            }

            return(obory);
        }
Esempio n. 4
0
 private static void PrepareCommand(SqlCommand command, Obor obor)
 {
     command.Parameters.AddWithValue("@IdObor", obor.IdObor);
     command.Parameters.AddWithValue("@Nazev", obor.Nazev);
     command.Parameters.AddWithValue("@Popis", obor.Popis);
 }