Click here to Skip to main content
12,072,067 members (57,570 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# .NET
c# code:
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 30-Apr-13 1:14am
Edited 30-Apr-13 7: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.
ryanb31 30-Apr-13 7:01am
   
What's the question?
patel_vijay 30-Apr-13 8:29am
   
Be more specific for your question? what is failing in your code?
ThePhantomUpvoter 30-Apr-13 12:50pm
   
In addition to not updating your code dump with an actual question, you are using an int "id" as if it were a string in your insert statement.
Member 9959371 30-Apr-13 13:20pm
   
iam also used string but no used.if u know ,u will answer me
ThePhantomUpvoter 30-Apr-13 14:23pm
   
That makes no sense at all. If your id is an integer, why are you using it as if it were a string in your insert statement?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100