Results 1 to 2 of 2

Thread: how to insert data from checkedlistbox into my sql database?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    208

    Question how to insert data from checkedlistbox into my sql database?

    i am developing windows form application and my database is Sql server 2005.

    i know how to insert from textbox into my table, but i got hard how to insert from checkedlistbox into my table.

    my table(customerTable) has two columns, customerName, and room.

    in my checkedlist box i have 1,2,,3,4,5........30,31,32 rooms list.

    i can select one or more rooms at the same time, for example, in the textbox of customerName i insert: Girmay Mekelle

    and the checkedlistBox lists: i can choose(tick) rooms: 10,13,18

    then click add button,

    then i expected the rooms in my table will be 10,13,18 and customerName:Girmay Mekelle.

    so how do i insert from checkedlistbox into my table?
    my second question is:
    if you can solve the above problem then , how do i select rooms from my table so that i can list them in checkedlistBox?

    i am a begginer and i tried to google it but i could not get the solution.

    so please forward ur help towards me. thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: how to insert data from checkedlistbox into my sql database?

    However you insert data from a TextBox is exactly how you insert data from a CheckedListBox. Data is data. It's how you get that data in the first place that differs depending on the source. The Text property of a TextBox is a String. To get Strings for checked items in a CheckedListBox, do something like this:
    csharp Code:
    1. foreach (var checkedItem in this.checkedListBox1.CheckedItems)
    2. {
    3.     MessageBox.Show(this.checkedListBox1.GetItemText(checkedItem));
    4. }
    Last edited by jmcilhinney; Feb 11th, 2011 at 06:23 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width