Click here to Skip to main content
12,758,135 members (32,750 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0 ASP.NET4

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 22-Dec-12 6:28am
Care to share where are you stuck here and what is the issue? Tried debugging? Any error?
arevant 22-Dec-12 7:05am
There is no debugging error generated but the values are not getting inserted into the table
Sheikh Muhammad Haris 22-Dec-12 9:13am
Have you verified your cmd.ExecuteNonQuery(); code block is executing ? Also, have you verified your query ?
jibesh 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2017
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