0 Replies - 1055 Views - Last Post: 07 December 2018 - 09:10 PM Rate Topic: -----

#1 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7056
  • View blog
  • Posts: 23,989
  • Joined: 05-May 12

Doing things the hard way...

Posted 07 December 2018 - 09:10 PM

From this C# thread...
private void btnUpdate_Click(object sender, EventArgs e)
		{
			double c = Convert.ToDouble(txtCNIC.Text);
			double m = Convert.ToDouble(txtMobile.Text);
			double t = Convert.ToDouble(txtResTel.Text);

			try
			{
				if (MetroMessageBox.Show(this, "Are you sure you want to update this record?", "MAARS Software", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
				{
					{
						// Update Data in Booking Table
						OleDbDataAdapter da = new OleDbDataAdapter("update [Booking] set NameApplicant='" + txtName.Text + "', FatherName='" + txtFName.Text + "', [Occupation]='" + txtOccupation.Text + "', MonthlyIncome=" + txtMonthlyIncome.Text + ", CNICNo=" + c + ", ApplicantAge='" + txtAAge.Text + "', ApplicantAddress='" + txtAddres.Text + "', MobileNo=" + m + ", ResidenceTel=" + t + ", EmailID='" + txtEmail.Text + "', NoOfDependents='" + txtNoOfDep.Text + "', [Nominee]='" + txtNominee.Text + "', ModifiedBy='" + lblLoginID.Text + "', ModiUserType='" + lblUserType.Text + "', ModifiedDate='" + datepicker.Value.Date.ToString() + "' where FormCode=" + txtFormCode.Text + " ", conn);
						DataSet ds = new DataSet();
						da.Fill(ds);
					}
					{
						// Update Data in Payment Table
						OleDbDataAdapter da = new OleDbDataAdapter("update [Payment] set NameApplicant='" + txtName.Text + "', FatherName='" + txtFName.Text + "', CNICNo=" + c + ", ApplicantAddress='" + txtAddres.Text + "', MobileNo=" + m + ", ResidenceTel=" + t + ", EmailID='" + txtEmail.Text + "', ModifiedBy='" + lblLoginID.Text + "', ModiUserType='" + lblUserType.Text + "', ModifiedDate='" + datepicker.Value.Date.ToString() + "' where FormCode=" + txtFormCode.Text + " ", conn);
						DataSet ds = new DataSet();
						da.Fill(ds);
						
					}
					ViewData();
					ClearAllCInfo();
					MetroMessageBox.Show(this, "User Data updated successfully", "MAARS Software", MessageBoxButtons.OK, MessageBoxIcon.Information);
					NewAppID();
				}

				else
				{

				}
			}
			catch (Exception ex)
			{
				MetroFramework.MetroMessageBox.Show(this, "Error" + ex.Message, "Stop", MessageBoxButtons.OK, MessageBoxIcon.Stop);
			}
		}



So wrong on so many levels... The thread has already touched on the regression back to concatenating a string instead of using parameters, as well as, the use of numeric values to store phone numbers and ID numbers.

What hasn't been touched on in the thread, yet, is the use of the OleDbAdapter and DataSet to write to the database instead of simply executing an OleDbCommand.

If that is the quality of code going into the MAARS Software, no wonder the company has been de-listed from the Bombay Stock Exchange at the end of 2016.

Is This A Good Question/Topic? 1
  • +

Page 1 of 1