Click here to Skip to main content
11,805,035 members (61,333 online)
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 0:14am
Edited 30-Apr-13 6: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 315
1 CPallini 210
2 Richard Deeming 200
3 Sergey Alexandrovich Kryukov 168
4 CHill60 150
0 OriginalGriff 3,255
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.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