Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
c# code:
C#
protected void btn_submit_Click(object sender, EventArgs e)
{
    if (chk_checkedbox.Checked == true)
    {
        SqlCommand sqlcom;
        int id = 1;
        sqlcon.Open();
        sqlcom = new SqlCommand("Select columname from tablename", sqlcon);
        id = Convert.ToInt16 (sqlcom.ExecuteScalar());
        sqlcon.Close();
    }
    else
    {
        SqlCommand sqlcm;
        int  id =0;
        sqlcon.Open();
        sqlcm = new SqlCommand("Select columname from tablename", sqlcon);
        id = Convert.ToInt16 (sqlcm.ExecuteScalar());
        sqlcon.Close();
    }

    SqlCommand sqlcom;
    sqlcon.Open();
    sqlcom = new SqlCommand("insert into tablename values('"+id+"')", sqlcon);
    sqlcom.ExecuteNonQuery();
    sqlcom.Dispose();
    sqlcon.Close();
}

plz solution it,,,,,,,,,,,
Posted
Updated 30-Apr-13 6:46am
v4
Comments
Orcun Iyigun 30-Apr-13 6:21am    
What the heck? What is your purpose? Explain it more detailed..
Prasad Khandekar 30-Apr-13 6:21am    
You are actually on right track. What's the problem with code? Not related to your problem but you may want to use SqlParameters with SqlCommand. It's the recommended way by experrts and will also safeguard you against SQLInjection attacks.

Regards,
Regards,
CHill60 30-Apr-13 6:32am    
You've used Select columname from tablename and are assigning the result to panch_id which is an int ... what do you really want panch_id to be? ExecuteScalar should be used to get a single value from the database, but in this case you will only get a single value if there is only one record on tablename.
ZurdoDev 30-Apr-13 7:01am    
What's the question?
vijay__p 30-Apr-13 8:29am    
Be more specific for your question? what is failing in your code?

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