Saving all listbox rows to a database

G

Guest

I have a web form that allow the user to add dates to a listbox control and
they are also added to an arraylist at the same time but I do not know how to
select all the rows into one string then save to the database.

Any suggestions?
 
A

alan.washington

I'm not really sure what you are trying to get at? Can you postmore details? You have values in a listbox and you have valuesin an arraylist. Are not both the arraylist and listbox thatsame (as you state)? If so just loop through either and runthem into a insert statement. Or will they select which datesthey want from the listbox and the selected one will be the onesinserted? If that is the case try the example below:

foreach(ListItem l in ListBox1.Items)
{
if(l.Selected)
{
Response.Write(l.Value); //or run insert here
}
}

Alan Washington
http://www.aewnet.com
I have a web form that allow the user to add dates to a listboxcontrol and
they are also added to an arraylist at the same time but I donot know how to
select all the rows into one string then save to the database.

Any suggestions?
User submitted from AEWNET (http://www.aewnet.com/)
 
G

Guest

I guess I am asking how do I loop through the listbox to save all the items
to the same database field? Do I need to use an update statement?

There has to be an easier way.

Thanks, Justin.
 
G

Guest

Hi ,
You can append the listitems as a comma seperated string and insert into the
database.
If you are looking for how to make the arraylist as a string then
Dim iCount As Integer = arStr.Count
Dim iIndex As Integer
Dim str As String
For iIndex = 0 To iCount - 1
str = str & arStr.Item(iIndex).ToString & ","
Next
where arStr is your arraylist.
You can now insert/update this to your database.
HTH
srini
 
G

Guest

Here is the code I have so far:

foreach (int i in EventDates.Items)
{
DateList += EventDates.Items.ToString();
}

Every time I try to execute this code the get this error on the foreach
statement: "Specified cast is not valid."

I don't know why this error is coming up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top