private void btnLendConfirm_Click(object sender, EventArgs e) { /*SqlConnection sc = new SqlConnection(); * SqlCommand com = new SqlCommand(); * sc.ConnectionString = ("Data Source = DESKTOP - A0H7M2N\\SQLEXPRESS; Initial Catalog = general; Integrated Security = True"); * sc.Open(); * com.Connection = sc; * com.CommandText = ("INSERT INTO Register (ContactNo, borrower_name) VALUES ('" + txtNumber.Text + "''" + txtName.Text + "');"); * com.ExecuteNonQuery(); * sc.Close(); * MessageBox.Show("Register Successful!");*/ DatabaseUtilities dbUtils = new DatabaseUtilities(); String name = txtName.Text; int contactNo = Int32.Parse(txtNumber.Text); //RESIDENT NUMBER SIZE try { dbUtils.addUser(new User(contactNo, name)); } catch { MessageBox.Show("Resident ID is already in use, Please Try Again!"); return; } MessageBox.Show("User is now Registered!", "Thank You."); //this.bookTableAdapter1.Fill(this.generalDataSet3.Book); // refreshTable(); // reset(); }
public void refreshTable() { SqlConnection conn = DatabaseUtilities.getConnection(); SqlCommand command = new SqlCommand(" select * from Borrowed_Book", conn); try { SqlDataAdapter sda = new SqlDataAdapter(); sda.SelectCommand = command; DataTable dbdataset = new DataTable(); sda.Fill(dbdataset); BindingSource bSource = new BindingSource(); bSource.DataSource = dbdataset; dgvBorrowedBooks.DataSource = bSource; sda.Update(dbdataset); //dgvBooks.AutoResizeColumns(); //dgvBooks.AutoSizeRowsMode = //DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }