コード例 #1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            int     searchId = Convert.ToInt32(textBoxClientId.Text);
            DataRow row      = dtClient.Rows.Find(searchId);

            if (row != null)
            {
                row["ClientName"]   = textBoxClientName.Text;
                row["Phone"]        = maskedTextBoxPhone.Text;
                row["CreditLimit"]  = float.Parse(textBoxCreditLimit.Text);
                row["StreetNumber"] = Convert.ToInt32(textBoxCreditLimit.Text);
                row["StreetName"]   = textBoxStreetName.Text;
                row["City"]         = textBoxCity.Text;
                row["PostalCode"]   = textBoxPostalCode.Text;
                row["Province"]     = textBoxProvince.Text;
                MessageBox.Show("In the DataSet obj, Student Info modified");
            }

            if (dsClient.HasChanges()) //DB
            {
                sqlDa        = UtilityDB.GetDataAdapterClients();
                sqlCmdClient = new SqlCommandBuilder(sqlDa);
                sqlDa.Update(dsClient.Tables["Clients"]);
                MessageBox.Show("Database updated successfully.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            int     deleteId = Convert.ToInt32(textBoxClientId.Text); //delete local
            DataRow dr       = dtClient.Rows.Find(deleteId);

            if (dr != null)
            {
                dr.Delete();
                MessageBox.Show("The Client was deleted.");
            }

            if (dsClient.HasChanges()) //Update DB
            {
                sqlDa        = UtilityDB.GetDataAdapterClients();
                sqlCmdClient = new SqlCommandBuilder(sqlDa);
                sqlDa.Update(dsClient.Tables["Clients"]);
                MessageBox.Show("Database updated successfully.", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }