Hi, how can i get multiple values in th listbox into my database???:confused:
Printable View
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.Quote:
Originally Posted by arunhere
You need to be more specific.
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:
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.Check out this page for information on ADO.NET.vb Code:
For Each item As String In myListBox.SelectedItems MessageBox.Show(item) Next item
But th code am looking for is in c#..........u have send me a vb code....:confused:
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#.
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
Thanks to both u guys i'll try it out......thaks once again:thumb: