473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ 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 2445
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(ListIte m 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.washingto n" 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(ListIte m 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(iInd ex).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.washingto n" 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.Item s)
{
DateList += EventDates.Item s[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(iInd ex).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.washingto n" 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
2460
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, what do I need to do in order to return the "option value" of the control? Moe !--- returned value of the control
3
5743
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 in the listbox. My FOR NEXT LOOP gets stuck on one record in the datatable. There are 4 records in the datatable and only the first one is selected. It never moves past the first record. MyCommand.Fill(dsCom, "tblCommRealtorAssociation") ...
5
4415
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 by 1 or more selected items from the listbox on the right after clicking an Add button. Clicking a "Remove" button will remove the item from the left listbox and restore it back to the right box.
2
1526
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 a listbox that needs to get data from an array. I call a function called GetAll that is a ArrayList in Customers that then calls CustomersDA.GetAll that is also an array list but returns customers (see code below).I need to fill a listbox from...
3
2429
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 ways. It does not appear to do much of anything. I was trying to use it to control the actual size in rows of the list box on the Web page. But the size of the Web listbox seems to be fixed and controlled by the size of the control set in the...
3
2001
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 record that the user is viewing but cannot be databound because other events and user input are needed when the user selects an item from the listbox. Each time the user clicks the binding navigator to move to the next record I have this: <code>
0
934
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 developing....the items would be added to the listbox with a "ADD TO CART" button and then the listbox wld display its productID name and QTY and price of the specific now to retrieve those values out of the listbox and delte the Qty of each item...
1
1339
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 you can help me. using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient;
0
944
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 stalls into the database i have to save according to number given in the textbox .but first i saved only two stallnames and next time i want to save the remaining stall names then it is not possible it checks the starting two stallnames and...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10222
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3967
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 we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.