Click here to Skip to main content
Rate this: bad
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;
        sqlcom = new SqlCommand("Select columname from tablename", sqlcon);
        id = Convert.ToInt16 (sqlcom.ExecuteScalar());
        SqlCommand sqlcm;
        int  id =0;
        sqlcm = new SqlCommand("Select columname from tablename", sqlcon);
        id = Convert.ToInt16 (sqlcm.ExecuteScalar());
    SqlCommand sqlcom;
    sqlcom = new SqlCommand("insert into tablename values('"+id+"')", sqlcon);
plz solution it,,,,,,,,,,,
Posted 30-Apr-13 1:14am
Edited 30-Apr-13 7:46am
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.
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 520
1 Maciej Los 205
2 Suvendu Shekhar Giri 159
3 Peter Leow 140
4 Kornfeld Eliyahu Peter 133
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2015
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