Results 1 to 8 of 8

Thread: Getting Multiple values from listbox to data base

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Getting Multiple values from listbox to data base

    Hi, how can i get multiple values in th listbox into my database???

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: Getting Multiple values from listbox to data base

    Quote Originally Posted by arunhere
    Hi, how can i get multiple values in th listbox into my database???
    Press the big red button at the center of your screen.

    You need to be more specific.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Re: Getting Multiple values from listbox to data base

    In my interface i have used a listbox. I want to know how can i link it to the database and save only the selected values in the listbox.

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

    Re: Getting Multiple values from listbox to data base

    You're asking two completely separate questions. Getting data from a ListBox is one thing. Saving data to a database is something else. If you think of them as black boxes then the first one has a pipe for its output and the second has a pipe for its input. You just have to connect the two pipes together and the output from one operation becomes the input for the other, but you should design the boxes independently.

    So, the SelectedItems property of a ListBox is a collection of the items that are selected. You can get them all by looping through the items with a For or For Each loop, e.g.
    vb Code:
    1. For Each item As String In myListBox.SelectedItems
    2.     MessageBox.Show(item)
    3. Next item
    Check out this page for information on ADO.NET.
    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Re: Getting Multiple values from listbox to data base

    But th code am looking for is in c#..........u have send me a vb code....

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

    Re: Getting Multiple values from listbox to data base

    Woops. Anyway, look at the code. It's a For Each loop and it enumerates the SelectedItems collection of the ListBox. You can write a foreach loop that enumerates the same property in C#.
    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

  7. #7
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Getting Multiple values from listbox to data base

    if you have a listbox with let's say names, you could use the event handler method to retrieve the name that the user selects. Then the other part is to add it to the database. Use a SQL insert statement to do this. It's 2 separate issues here as Jhil said.

    Jennifer

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    16

    Re: Getting Multiple values from listbox to data base

    Thanks to both u guys i'll try it out......thaks once again

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