示例#1
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string conResident = ConfigurationManager.ConnectionStrings["conResident"].ConnectionString;
                string addQuery    = "INSERT into Residents(FirstName,LastName,ResidentTypeName,FloorID,DormID,HoursWorked,TotalRent) VALUES('"
                                     + FirstName.Text + "','" + LastName.Text + "','" + ResidentTypeName.Text + "','" + FloorID.Text + "','" + DormID.Text +
                                     "','" + HoursWorked.Text + "','" + TotalRent.Text + "');";
                SqlConnection addConn = new SqlConnection(conResident);
                SqlCommand    addCmd  = new SqlCommand(addQuery, addConn);
                SqlDataReader addReader;
                addConn.Open();
                addReader = addCmd.ExecuteReader();
                MessageBox.Show("Data saved");
                while (addReader.Read())
                {
                }
                addConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            AddNew Add = new AddNew();

            Add.Show();
            Close();
        }
        private void BtnAddNew_Click(object sender, RoutedEventArgs e)
        {
            AddNew addNew = new AddNew();

            addNew.Show();
            Close();
        }