Click here to Skip to main content
Rate this: bad
good
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 at 30-Apr-13 6:21am
   
What the heck? What is your purpose? Explain it more detailed..
Prasad Khandekar at 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 at 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 at 30-Apr-13 7:01am
   
What's the question?
patel_vijay at 30-Apr-13 8:29am
   
Be more specific for your question? what is failing in your code?
ThePhantomUpvoter at 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 at 30-Apr-13 13:20pm
   
iam also used string but no used.if u know ,u will answer me
ThePhantomUpvoter at 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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 BillWoodruff 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
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