Пример #1
0
        public static void DeleteBook(Book book)
        {
            SqlConnection conDb = UtilityDB.ConnectDB();
            SqlCommand    cmd   = new SqlCommand();

            cmd.Connection  = conDb;
            cmd.CommandText = string.Format("DELETE from book where isbn = '" + book.isbn + "'");
            cmd.ExecuteNonQuery();
            connDb.Close();
        }
Пример #2
0
        public static void SaveBook(Book book)
        {
            SqlConnection connDb = UtilityDB.ConnectDB();
            SqlCommand    cmd    = new SqlCommand();

            cmd.Connection  = connDb;
            cmd.CommandText = string.Format("insert into book (isbn, title, author) values ({0},'{1}','{2}') ", book.isbn, book.title, book.author);
            cmd.ExecuteNonQuery();
            connDb.Close();
        }
Пример #3
0
        public static void UpdateBook(Book book)
        {
            SqlConnection conDb = UtilityDB.ConnectDB();
            SqlCommand    cmd   = new SqlCommand();

            cmd.Connection  = conDb;
            cmd.CommandText = string.Format("update book SET isbn = '" + book.isbn + "',title='" + book.title + "',author='" + book.author + "'WHERE isbn = '" + book.isbn + "'");
            cmd.ExecuteNonQuery();
            connDb.Close();
        }
Пример #4
0
        public static DataTable ReadBook()
        {
            connDb          = UtilityDB.ConnectDB();
            cmd             = new SqlCommand();
            cmd.Connection  = connDb;
            cmd.CommandText = "select * from book";
            SqlDataReader reader = cmd.ExecuteReader();
            DataTable     dt     = new DataTable();

            dt.Load(reader);
            reader.Close();

            cmd.Dispose();
            connDb.Close();
            return(dt);
        }
Пример #5
0
        public static DataTable SearchBook(int id)
        {
            SqlConnection connDb = UtilityDB.ConnectDB();
            SqlCommand    cmd    = new SqlCommand();

            cmd.Connection  = connDb;
            cmd.CommandText = "select * from book where isbn= " + id;
            SqlDataReader reader = cmd.ExecuteReader();
            DataTable     dt     = new DataTable();

            dt.Load(reader);
            reader.Close();
            cmd.Dispose();
            // cmd.ExecuteNonQuery();
            connDb.Close();
            return(dt);
        }