private void ordersView_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (ordersView.Columns[e.ColumnIndex].Name == "delete") { if (MessageBox.Show("Are you sure? ", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DataGridViewRow row = ordersView.Rows[e.RowIndex]; Console.WriteLine(row.Cells["ID"].Value); int orderId = (int)row.Cells["ID"].Value; using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); string query = "DELETE FROM ClientOrder WHERE Id = " + orderId; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteReader(); this.Hide(); OrderClerkDashboard dashboard = new OrderClerkDashboard(); dashboard.Show(); } } } }
private void button1_Click(object sender, EventArgs e) { string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\14383\Downloads\BookBizz\BookBizz\Database1.mdf;Integrated Security=True"; int client = clientId; int book = bookId; int quantity = Int32.Parse(qty.Text); int payment = Int32.Parse(orderPayment.Text); if (orderErrorCont.Visible == false) { using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); string query = "INSERT INTO ClientOrder VALUES " + "(" + client + ", " + book + ", " + quantity + ", " + payment + ")"; SqlCommand cmd = new SqlCommand(query, con); cmd.ExecuteReader(); } } this.Hide(); OrderClerkDashboard dashboard = new OrderClerkDashboard(); dashboard.Show(); }