WORK 12 บันทึกข้อมูลลงตาราง


                          Code : FormBooks.cs
                                       ButtonSaveClick  :
                                           {
                                           String dbName = "kvcLib.ldb";
                                           String dataSource = "data source= " + dbName;
                                           SQLiteConnection con = new SQLiteConnection(dataSource);
                                           SQLiteCommand com = new SQLiteCommand(dataSource, con);

                                           String bookName = textBoxBookName.Text;
                                           String author = textBoxAuthor.Text;
                                           int publishedYear = Int16.Parse(textBoxPublishedYear.Text);
                                           String shelf = textBoxShelf.Text;
                                           String isbn = textBoxISBN.Text;

                                           String qry = "INSERT into books " +
                                            "(BookName, Author, Published_year, " +
                                            "Shelf, ISBN) Values(@bookName, @author, " +
                                            "@publishedYear, @shelf, @isbn)";
                                            con.Open();

                                            com.CommandText = qry;
                                            com.Parameters.Add("@bookName", DbType.String).Value = bookName;
                                            com.Parameters.Add("@author", DbType.String).Value = author;
                                            com.Parameters.Add("@publishedYear", DbType.Int32).Value = publishedYear;
                                            com.Parameters.Add("@shelf", DbType.String).Value = shelf;
                                            com.Parameters.Add("@isbn", DbType.String).Value = isbn;
                                                try {
                                                    om.ExecuteNonQuery();
                                                    MessageBox.Show("บันทึกข้อมูลสำเร็จ");
                                               } catch (Exception ex) {
                                                    MessageBox.Show("มีความผิดพลาด บันทึกข้อมูลไม่สำเร็จ\n" + ex.ToString());
                                               }
                                               con.Close();
                                               }