コード例 #1
0
        //--------------deleting customer-------------------------------------------------------------------------------------
        private void DeleteCus_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand    command    = new SqlCommand();

            connection.ConnectionString = @"Data Source=BRTHDYBYROJY\SQLEXPRESS;" + "Initial Catalog=steptest; Integrated Security=YES";
            command.Connection          = connection; command.CommandText = "DELETE FROM Customer WHERE Cus_id=@CusID";
            command.Parameters.AddWithValue("@CusID", Cusid.Text);
            try
            {
                connection.Open(); int result = command.ExecuteNonQuery();
                if (result > 0)
                {
                    MessageBox.Show("Congratulations! Customer has been deleted.");
                    Customerlogin backagain = new Customerlogin();
                    backagain.Show();
                }
                else
                {
                    MessageBox.Show("Unable to delete the customer,Can't find Customer.please check the staff id.");
                }
            }
            catch
            (SqlException)
            {
                MessageBox.Show("An error has occured.");
            }
            finally
            {
                connection.Close();
            }
        }
コード例 #2
0
        private void Submit_Click(object sender, EventArgs e)
        {
            SqlConnection connection = new SqlConnection();
            SqlCommand    command    = new SqlCommand();

            connection.ConnectionString = @"Data Source=BRTHDYBYROJY\SQLEXPRESS;" + "Initial Catalog=steptest; Integrated Security=YES";
            command.Connection          = connection;
            command.CommandText         = "SELECT * FROM Staff WHERE Staff_id=@StaffID";
            command.Parameters.Clear();
            command.Parameters.AddWithValue("@StaffID", Staffid.Text);
            try
            {
                connection.Open();

                reader = command.ExecuteReader(CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    textBox1.Text = reader["Staff_name"].ToString();

                    Class1.sname = textBox1.Text;
                    Customerlogin sec = new Customerlogin();
                    sec.Show();
                }
                else
                {
                    MessageBox.Show("StaffID does not exist.");
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally { connection.Close(); }
        }