473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to read comma seperated value in the listbox

Hi,
I have a registration form where i am using a listbox where we can select multiple values.I am storing these values concatenating with commas(for eg. A,B,C).Now i have to update this registration form, so i have to retrieve these values.
I have the idea that first i have to retrieve that field from database and split the commas and then i have to write the code in the front end to display the values.
But in real time i m unable to display in front end.
Can anyone help me.

have the following code to bind the data from a table to listbox.Sub ListLoad()
' ||||| DECLARE VARIABLES |||||
Dim mystring As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(mystring, dbconn)
Dim objReader As SqlDataReader
Dim objReader As SqlDataReader
Dim delimStr As String = ","

Dim delimiter As Char() = delimStr.ToCharArray()
Dim s As String
For Each s In strProducts.Split(delimiter)
Response.Write((s.ToString() + "<br>"))
Dim Cmd As New SqlCommand(mystring, dbconn)
Next
Try
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
lstselectedemployees.Items.Clear()
lstselectedemployees.DataTextField = "Swinstalled"
lstselectedemployees.DataSource = objReader
lstselectedemployees.DataBind()
objReader.Close()
Catch ex As Exception
MsgBox("Error Connecting to Database!", MsgBoxStyle.Critical)
End Try
Thanks and regards
Aug 20 '07 #1
3 2729
nateraaaa
663 Expert 512MB
Hi,
I have a registration form where i am using a listbox where we can select multiple values.I am storing these values concatenating with commas(for eg. A,B,C).Now i have to update this registration form, so i have to retrieve these values.
I have the idea that first i have to retrieve that field from database and split the commas and then i have to write the code in the front end to display the values.
But in real time i m unable to display in front end.
Can anyone help me.

have the following code to bind the data from a table to listbox.Sub ListLoad()
' ||||| DECLARE VARIABLES |||||
Dim mystring As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(mystring, dbconn)
Dim objReader As SqlDataReader
Dim objReader As SqlDataReader
Dim delimStr As String = ","

Dim delimiter As Char() = delimStr.ToCharArray()
Dim s As String
For Each s In strProducts.Split(delimiter)
Response.Write((s.ToString() + "<br>"))
Dim Cmd As New SqlCommand(mystring, dbconn)
Next
Try
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
lstselectedemployees.Items.Clear()
lstselectedemployees.DataTextField = "Swinstalled"
lstselectedemployees.DataSource = objReader
lstselectedemployees.DataBind()
objReader.Close()
Catch ex As Exception
MsgBox("Error Connecting to Database!", MsgBoxStyle.Critical)
End Try
Thanks and regards
Why do you have 2 datareaders initialized with the same name? Also will any of your data in the listbox contain commas? If so you may want to make your delimiter a different character, such as a | or a _ . Try removing one of the objReader declarations. Also check the contents of your listbox using the debugger to make sure that your listbox is being populated when you call .DataBind().

Nathan
Aug 20 '07 #2
Why do you have 2 datareaders initialized with the same name? Also will any of your data in the listbox contain commas? If so you may want to make your delimiter a different character, such as a | or a _ . Try removing one of the objReader declarations. Also check the contents of your listbox using the debugger to make sure that your listbox is being populated when you call .DataBind().

Nathan

By mistake i have given 2 datareaders. But still i know something is missing in my code. I am not binding split function with listbox(lstselectedemployees). I dont know how to do that.
Aug 21 '07 #3
By mistake i have given 2 datareaders. But still i know something is missing in my code. I am not binding split function with listbox(lstselectedemployees). I dont know how to do that.

But, How do I bind that to a listbox.

I am working in asp.net 2.0 and using vb script.

Let us assume i have table "A_desktops" with columns assetcode and swinstalled.

Assecode Swinstalled
D001 sql,vb,Sap
D002 vs 2005, sql 2005
D003 Microsoft SQL Server 2000 Microsoft Office 97, Std Edition SAP

When i bind the data based on asset code say D003 to listbox it bind as Microsoft SQL Server 2000 Microsoft Office 97, Std Edition SAP But i want them to display different listitems after comma.



I have tried the following code also, but something is missing, some connectivity may be but i could not figure it out

Sub ListLoad()
' ||||| DECLARE VARIABLES |||||
Dim strProducts As String = "select swinstalled from a_desktops where assetcode='" & TextBox1.Text & "'"
Dim Cmd As New SqlCommand(strProducts, dbconn)
Dim objReader As SqlDataReader

Dim itemArray() As String = strProducts.Split(",")


Try
If dbconn.State = ConnectionState.Closed Then
dbconn.Open()
End If
objReader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)
lstselectedemployees.Items.Clear()
lstselectedemployees.DataTextField = "Swinstalled"
lstselectedemployees.DataSource = objReader
lstselectedemployees.DataBind()
objReader.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try[/quote]
Aug 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jong Choi | last post by:
Dear All, I am trying to open the file(walk5.dat) and then read the data The structures of data are 0, 0, -10, -10, 0, -8.1,-12,-10 , 0,-14,-10,-7,0, 6.096666667,-10,-10,1, ...
11
by: Craig Keightley | last post by:
I have a mysql database with a list of companies who supply specific products tblSuppliers (simplified) sID | sName | goodsRefs 1 | comp name | 1,2,3,4,5 2 | company 2 | 2,4
11
by: Shawn Odekirk | last post by:
Some code I have inherited contains a macro like the following: #define setState(state, newstate) \ (state >= newstate) ? \ (fprintf(stderr, "Illegal...
7
by: Sick | last post by:
My application populates a ListBox from a .TXT file. In the textfile there are prices with both dots as well as comma's for decimal indication. Example: 1234990; xg-tr-45; 1700,50; 0 2662666;...
3
by: dfetrow410 | last post by:
I need make a comma seperated list, but whwn I build the list I get a comma at the end. How do I remove it? foreach (ListItem lst in REIPropertyType.Items) { if (lst.Selected == true) {...
3
by: xuxf055 | last post by:
Hi Everybody, I am confused for a few days, how to read the data file seperated by comma. for exampe following file. data.txt 1,2,3,4,5,6,7,8,9,10 11,12,13,14,15,16,17,18,19,20 how to read it...
2
nehashri
by: nehashri | last post by:
i hv a database in access wid Asp as front end. ven given a word in search command(of the front end) it shud go to a table in which each field has words serated by comma. each word shud b checked...
2
by: Siva73 | last post by:
Hi I want to return a set of value with comma seperated in a single row with out using cursorts. Eg. Col 1 A A B
0
by: Kristi | last post by:
I need to create a CL program that will take a PF, and create a tab delimited file that has comma seperated column headings as the first record. I know i can use cpytostmf/cpytoimpf to create the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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,...
0
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...
0
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,...
0
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...
0
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...

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.