VBForums >
.NET >
C# > Getting Multiple values from listbox to data base
Click to See Complete Forum and Search --> : Getting Multiple values from listbox to data base
arunhere
May 11th, 2007, 05:15 AM
Hi, how can i get multiple values in th listbox into my database???:confused:
vbNeo
May 14th, 2007, 03:22 PM
Hi, how can i get multiple values in th listbox into my database???:confused:
Press the big red button at the center of your screen.
You need to be more specific.
arunhere
May 20th, 2007, 11:56 PM
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.:confused:
jmcilhinney
May 21st, 2007, 01:26 AM
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.For Each item As String In myListBox.SelectedItems
MessageBox.Show(item)
Next itemCheck out this page (http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/adoplusoverview.aspx) for information on ADO.NET.
arunhere
May 21st, 2007, 05:30 AM
But th code am looking for is in c#..........u have send me a vb code....:confused:
jmcilhinney
May 21st, 2007, 05:47 AM
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#.
JenniferBabe
May 21st, 2007, 08:16 AM
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
arunhere
May 22nd, 2007, 01:24 AM
Thanks to both u guys i'll try it out......thaks once again:thumb:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.