private void Update_Record_Click(object sender, EventArgs e)
{
ConnectionClass.OpenConnection();
if (textBox4.Text == "" && textBox2.Text == "")
{
MessageBox.Show("No value entred for update.");
}
else if (textBox4.Text != "" && textBox2.Text != "")
{
SqlCommand cmd = new SqlCommand("update medicinerecord set quantity='" + textBox2.Text + "' where productid='"+comboBox1.Text+"'", ConnectionClass.OpenConnection());
cmd.ExecuteNonQuery();
cmd = new SqlCommand("update myrecord set price='" + textBox4.Text + "' where productid='" + comboBox1.Text + "'", ConnectionClass.OpenConnection());
cmd.ExecuteNonQuery();
ConnectionClass.CloseConnection();
}
else if (textBox2.Text != "")
{
SqlCommand cmd = new SqlCommand("update myrecord set quantity='" + textBox2.Text + "' where productid='" + comboBox1.Text + "'", ConnectionClass.OpenConnection());
cmd.ExecuteNonQuery();
ConnectionClass.CloseConnection();
}
else if (textBox4.Text != "")
{
SqlCommand cmd = new SqlCommand("update myrecord set price='" + textBox4.Text + "' where productid='" + comboBox1.Text + "'", ConnectionClass.OpenConnection());
cmd.ExecuteNonQuery();
ConnectionClass.CloseConnection();
}
}
It's working correctly but I want to make it shorter so that it's easier to understand. How can I refactor it?