public bool existPationts()
{
con.Open();
s = "select * from Patients where P_id = " +
Convert.ToString(txt_Pid.Text);
sCommand = new SqlCommand(s, con);
int isexist;
isexist = Convert.ToInt32(sCommand.ExecuteScalar());
if(isexist > 0)
{
MessageBox.Show("its exist");
txt_Pid.Focus();
txt_Pid.Clear();
return true;
con.Close();
}
else
{
return false;
con.Close();
}
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
if(!existPationts())
{
Validation();
if (validateID == true && validateName == true && validatePhone1
== true && validateRadio == true && validateCB_City == true
&& validateCB_Center == true && validateCB_doctor ==
true && validateCB_Side == true)
{
if (MessageBox.Show("Are you want save?", "save", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
s = "insert into Patients (P_id, P_Name, P_Gender,
P_DateOfBirth, City_id, Center_id, Phone1, Phone2,
Doctor_id, Side_id, P_Weight, P_Length, Notes)";
s = s + "values (@P_id, @P_Name, @P_Gender,
@P_DateOfBirth, @City_id, @Center_id, @Phone1, @Phone2,
@Doctor_id, @Side_id, @P_Weight, @P_Length, @Notes)";
sCommand = new SqlCommand(s, con);
con.Open();
sCommand.Parameters.AddWithValue("@P_id", txt_Pid.Text);
sCommand.Parameters.AddWithValue("@P_Name",
txt_PName.Text);
sCommand.Parameters.AddWithValue("@P_Gender", x);
sCommand.Parameters.AddWithValue("@P_DateOfBirth",
dtp_PBirthDate.Text);
sCommand.Parameters.AddWithValue("@City_id",
CB_City.SelectedValue);
sCommand.Parameters.AddWithValue("@Center_id",
CB_Center.SelectedValue);
sCommand.Parameters.AddWithValue("@Phone1",
txt_Phone1.Text);
sCommand.Parameters.AddWithValue("@Phone2",
txt_Phone2.Text);
sCommand.Parameters.AddWithValue("@Doctor_id",
CB_Doctor.SelectedValue);
sCommand.Parameters.AddWithValue("@Side_id",
CB_Side.SelectedValue);
sCommand.Parameters.AddWithValue("@P_Weight",
txt_Weight.Text);
sCommand.Parameters.AddWithValue("@P_Length",
txt_Length.Text);
sCommand.Parameters.AddWithValue("@Notes",
txt_Notes.Text);
sCommand.ExecuteNonQuery();
con.Close();
MessageBox.Show("it's saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Cancel");
}
}
}
}
catch
{
return;
}
}
What I have tried:
How i solve this problem in this code