Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# C#4.0 ASP.NET4.0
I was stuck in middle. Was not able to insert values into the DB. Could u please help me out.
Thanks in advance.
My code is:
public void savetoDB()
           string qry = null;
           string inputvalue = null;
           int i = 0;
           for (i = 0; i <= CheckBoxList2.Items.Count - 1; i++)
               if (CheckBoxList2.Items[i].Selected == true)
                   inputvalue = CheckBoxList2.Items[i].Text;
                   qry = "INSERT INTO DART_IDC_ADD_PROC_MAP(DAR_ID,ADD_PROC_SEL) VALUES (123,'" + inputvalue + "')";
                   SqlCommand cmd = new SqlCommand(qry, con1);

ASP Code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
          <asp:CheckBoxList ID="CheckBoxList2" runat="server" AppendDataBoundItems="True"
      <br />
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
      <br />
Posted 22-Dec-12 1:09am
Sandeep Mewara at 22-Dec-12 6:28am
Care to share where are you stuck here and what is the issue? Tried debugging? Any error?
arevant at 22-Dec-12 7:05am
There is no debugging error generated but the values are not getting inserted into the table
Sheikh Muhammad Haris at 22-Dec-12 9:13am
Have you verified your cmd.ExecuteNonQuery(); code block is executing ? Also, have you verified your query ?
jibesh at 22-Dec-12 9:28am
why you are posting same query with different caption.
You can use 'Improve Question' link at the right bottom of your question to make any changes to your query. do not post same query multiple times.
Sheikh Muhammad Haris at 22-Dec-12 9:51am
I think both are same, right ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try replacing
inputvalue = CheckBoxList2.Items[i].Text
inputvalue = CheckBoxList2.Items[i].ToString
I think there's your problem.
Hope it will help you,

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

  Print Answers RSS
0 OriginalGriff 680
1 Maciej Los 300
2 Suvendu Shekhar Giri 229
3 Sascha Lefévre 229
4 Richard Deeming 195
0 Sergey Alexandrovich Kryukov 9,678
1 OriginalGriff 9,135
2 Peter Leow 5,082
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,606

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 23 Dec 2012
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