Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6842019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:02:45+00:00 2026-05-27T00:02:45+00:00

i have used a checkbox list in my project .am storing all the checked

  • 0

i have used a checkbox list in my project .am storing all the checked items values in arraylist using code below

 ArrayList  services= new ArrayList();
for (int i = 0; i < chkservices.Items.Count; i++)
        {
            if (chkservices.Items[i].Selected == true)
            {
                services.Add(chkservices.Items[i].Text+',');
            }
        }

now the problem is when i insert data in to database instead of data in the arraylist it gets inserted as ‘System.Collections.ArrayList‘ how can i insert all values into database in a single insert statement?

EDIT

inserting into database

con.Open();
        SqlCommand cmd = new SqlCommand("insert into XXX(First_Name,Last_Name,ServicesProvided) values ('" + txtfrstname.Text + "','" + txtlastname.Text + "','" + services + "')", con);
        cmd.ExecuteNonQuery();
        con.Close();

or could anyone provide me a alternative for arraylist..i need to save checked items from checkboxlist and save it in database

it should be saved in database as

  First_Name             Last_name                 ServicesProvided
user1firstname        user1lastname               selectedvalue1,
                                              selectedvalue2,selectedvalue3
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:02:46+00:00Added an answer on May 27, 2026 at 12:02 am

    Why not to concatenate your data using the following code:

     var mydata = String.Join(',', chkservices.Items
       .Where( a => a.Selected).Select( b => b.Text));
    

    So you can add your data as a string.

    EDIT:
    It is a very bad habit of concatenating strings to make a query! Apart from many side effects like in your case here it is a great security breach. Try the parameterized query instead:

         SqlCommand cmd = new SqlCommand(
             @"insert into XXX(First_Name,Last_Name,ServicesProvided) values 
             (@First_Name,@Last_Name,@ServicesProvided")", con); 
          cmd.Parameters.AddWithValue("@ServicesProvided", mydata);
          cmd.Parameters.AddWithValue("@First_Name", frstname.Text);
          cmd.Parameters.AddWithValue("@Last_Name", txtlastname.Text);
        cmd.ExecuteNonQuery();
    

    mydata is the variable from my first example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a checkboxlist in Popup. I used a selectall checkboxlist items function in
I have created a Treeview and used a stack panel to include a checkbox,
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I have used ModalpopupExtender control in my web page. I have checkbox for selectall
I Have List of Products Displayed with in an Unordered List as Below. When
Using CakePHP 1.3.6 I'm sure I may have to add code and examples, but
If you have ever used SQL reporting services, there are some dropdown lists that
I have added a checkbox inside a list view, but i am able to
I have a checkbox list of sports which is bound to an observable collection
I have used the silverlight control in CRM 2011.It also published on form but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.