|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have a checked listbox being populated from a database using a data reader.The form loades correctly now I want to cycle through the items checked and get the GUID assiciated for each location this will be passed to a stored procedure for insert/updating a database can anyone help I'm confussed ????
Dim commandSql2 As New SqlClient.SqlCommand() commandSql2.Connection = conSqlOral commandSql2.CommandText = "Select Location_Name,Location_Street,Location_City,Locati on_Guid from Location Where Location_Oral is NOT null Order by Location_Name" Dim datReadOral As SqlClient.SqlDataReader datReadOral = commandSql2.ExecuteReader Dim HoldGuidOral As String Dim strGuidOral As String Do Until datReadOral.Read = False chkOralLocations.Items.Add(datReadOral.GetValue(0) & " " & datReadOral.GetValue(1) & " " & datReadOral.GetValue(2)) strGuidOral = datReadOral.GetValue(3).ToString '& " " & datReadOral.GetValue(3).ToString HoldGuidOral = HoldGuidOral & ", " & strGuidOral 'HOLDS THE NAME AND ORAL LOCATION GUIDS Loop conSqlOral.Close() I = 0 For I = 0 To chkOralLocations.Items.Count - 1 If chkOralLocations.GetItemChecked(I) = True Then HoldOralLocations = HoldOralLocations & " " & chkOralLocations. All I get is the locations but no guid's ??? |
|
#2
|
|||
|
|||
|
Your problem is, your list is only storing the locations, that is why you aren't getting the location's GUID. I see that you are storing the GUIDs, just not using them or even creating a link between them and the list box.
What you should do is, read the GUIDs into a comma separated string like you have, but after you get out of the read loop, SPLIT the string into an array. This way, if you have a location in the list at index 5, your array has the corresponding GUID also at index 5 (both the list and the array index will start at 0). Code:
' ... code
Do Until datReadOral.Read = False
strLocationName = datReadOral("Location_Name")
strLocationStreet = datReadOral("Location_Street")
strLocationCity = datReadOral("Location_City")
intLocationGUID = datReadOral("Location_Guid")
strGUIDs = strGUIDs & intLocationGUID & ","
chkOralLocations.Items.Add(strLocationName & " " & _
strLocationStreet & " " & strLocationCity)
Loop
conSqlOral.Close()
If Len(strGUIDs) > 0 Then
strGUIDs = Left(strGUIDs, Len(strGUIDs)-1)
End If
arrGUIDs = Split(strGUIDs, ",")
For I = 0 To chkOralLocations.Items.Count - 1
If chkOralLocations.GetItemChecked(I) = True Then
intThisGUID = arrGUIDs(I)
strSelectedGUIDs = strSelectedGUIDs & intThisGUID & ","
End If
Next
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Guid's |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|