Beispiel #1
0
 // Update Customer Button(This button used for update customer details
 private void UpdateCustomer_Click(object sender, EventArgs e)
 {
     con.Open();// Connection Open
     comm = new SqlCommand("update Customer set CId= '" + CustomerID.Text + "', FName= '" + CustomerName.Text + "', LName='" + CustomerLastName.Text + "', CAddress='" + CustomerAddress.Text + "', CPhoneNo='" + CustomerPhone.Text + "' where CId = '" + CustomerID.Text + "'", con);
     try
     {
         comm.ExecuteNonQuery();
         MessageBox.Show("Customer Updated");
         con.Close();// Connection Close
         ShowcustRecord();
         CustomerID.Clear();
         CustomerName.Clear();
         CustomerLastName.Clear();
         CustomerAddress.Clear();
         CustomerPhone.Clear();
     }
     catch (Exception)
     {
         MessageBox.Show("Customer Not Updated");
     }
     finally
     {
         con.Close();// Connection Close
     }
 }
Beispiel #2
0
 private void CustomerInsert_Click(object sender, EventArgs e) // Customer Insert Button(When I click on insert button the data will insert in Table)
 {
     con.Open();                                               // Connection Open
     comm = new SqlCommand("insert into Customer values('" + CustomerID.Text + "','" + CustomerName.Text + "','" + CustomerLastName.Text + "','" + CustomerAddress.Text + "','" + CustomerPhone.Text + "')", con);
     try
     {
         comm.ExecuteNonQuery();
         MessageBox.Show("Customer Saved"); // Message Box (Its show the saved customers)
         con.Close();                       // Connection Close
         ShowcustRecord();
         CustomerID.Clear();
         CustomerName.Clear();
         CustomerLastName.Clear();
         CustomerAddress.Clear();
         CustomerPhone.Clear();
     }
     catch (Exception)
     {
         MessageBox.Show("Customer Not Saved");    // Message Box
     }
     finally
     {
         con.Close();    // Connection Close
     }
 }
Beispiel #3
0
 // Delete Customer Button(This button used for delete the customer)
 private void DeleteCustomer_Click(object sender, EventArgs e)
 {
     con.Open();// Connection Open
     comm = new SqlCommand("delete from Customer where CId = " + CustomerID.Text + " ", con);
     try
     {
         comm.ExecuteNonQuery();
         MessageBox.Show("Customer Deleted");
         con.Close();// Connection Close
         ShowcustRecord();
         CustomerID.Clear();
         CustomerName.Clear();
         CustomerLastName.Clear();
         CustomerAddress.Clear();
         CustomerPhone.Clear();
         CustomerID.Focus();
     }
     catch (Exception x)
     {
         MessageBox.Show("Customer Not Deleted" + x.Message);
     }
     finally
     {
         con.Close();// Connection Close
     }
 }