Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void btnAddQueue_Click(object sender, EventArgs e)
        {
            if (RadioNEW.Checked)
            {
                SqlConnection sc = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["hospitalmanagementdb"].ToString());
                SqlCommand cmd = new SqlCommand("insert into patient values('" + txtFirstnm.Text + "','" + txtLastnm.Text + "','" + RadioMF.Text + "','" + txtAge.Text + "','" + txtContact.Text + "','" + txtEmail.Text + "','" + txtAddress.Text + "')", sc);

                sc.Open();
                cmd.ExecuteNonQuery();
                sc.Close();
            }
            else
            {
                SqlConnection sc = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["hospitalmanagementdb"].ToString());
                sc.Open();
                SqlCommand cm = new SqlCommand("insert into appointment values((select max(patient_id) from patient),'" + dropQueue.SelectedValue.ToString() + "','" + System.DateTime.Today.Date.ToString() + "','treated')", sc);
                cm.ExecuteNonQuery();
                sc.Close();
            }
        }

In appointment table the patient id is not passing same id is showing in all data. Data is passed but only id is not working.
Posted
Updated 25-Mar-14 9:23am
v2
Comments
Sergey Alexandrovich Kryukov 25-Mar-14 15:43pm    
"id is not working" in not informative...
—SA

1 solution

C#
protected void btnAddQueue_Click(object sender, EventArgs e)
{
    string query = string.Empty;
    if (RadioNEW.Checked)
    {
        query = "insert into patient values('" + txtFirstnm.Text + "','" + txtLastnm.Text + "','" + RadioMF.Text + "','" + txtAge.Text + "','" + txtContact.Text + "','" + txtEmail.Text + "','" + txtAddress.Text + "')";
    }
    else
    {
        query = "insert into appointment values((IDENT_CURRENT('patient')),'" + dropQueue.SelectedValue.ToString() + "','" + System.DateTime.Today.Date.ToString() + "','treated')"
    }
    
    using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["hospitalmanagementdb"].ToString()))
    {
        using(SqlCommand cmd = new SqlCommand(query, conn))
        {
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }

}


It's highly recomended that you use storeprocedure in order to use IDENT_CURRENT() inside it. More info about IDENT_CURRENT(TABLE) here[^].

Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900