473,466 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Saving all listbox rows to a database

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?
Nov 18 '05 #1
4 2420
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/)
Nov 18 '05 #2
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.

"alan.washington" wrote:
I'm not really sure what you are trying to get at? Can you post more details? You have values in a listbox and you have values in an arraylist. Are not both the arraylist and listbox that same (as you state)? If so just loop through either and run them into a insert statement. Or will they select which dates they want from the listbox and the selected one will be the ones inserted? 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 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?

User submitted from AEWNET (http://www.aewnet.com/)

Nov 18 '05 #3
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
"Justin" wrote:
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.

"alan.washington" wrote:
I'm not really sure what you are trying to get at? Can you post more details?

Nov 18 '05 #4
Here is the code I have so far:

foreach (int i in EventDates.Items)
{
DateList += EventDates.Items[i].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.
"srini" wrote:
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
"Justin" wrote:
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.

"alan.washington" wrote:
I'm not really sure what you are trying to get at? Can you post more details?

Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
3
by: Big E | last post by:
I'm using ASP.Net and SQL Server. I have a listbox looks up data from a table and fills the listbox. I have a stored procedure that looks up the selected values and tries to show them as selected...
5
by: Dave | last post by:
Hi All, I have a windows form that contains 2 listboxes and 2 buttons. The listbox on the right is populated by a database routine (This is the easy part). The listbox on the left is populated...
2
by: Allen | last post by:
Hey all, I have a question for you all. I'm learning vb.net and need some help. I have two classes one named Customers and one named CustomersDA. I have to go though Customer for everything. I have...
3
by: Hugh O | last post by:
Hi, There is a ROW property on the Web Listbox control within VB.Net. The description states it is "The number of visible rows to display". I have tried setting this property in many different...
3
by: Angel Blue01 | last post by:
I have a form with a binding navigator that draws from a database via drag-and-drop-created controls. I'm filling a listbox with the results of a query. The listbox contains data related to the...
0
OuTCasT
by: OuTCasT | last post by:
This is how a person would go about selecting certain values from a listbox that they want to delete from a database..... usually a person would use this code for say an INVOICE system they were...
1
by: romcab | last post by:
Hi guys, I would like to ask your help about saving in ado.net. I was able to update it only on the display but when I check the database, it is not updated. I paste below my code and hopefully...
0
by: madhu raju | last post by:
iam saving the data into Ms-Access database using Vb.net Application In that application iam using Data grid view to save the data into the database Here in the below code iam saving the name of...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.