Connecting Tech Pros Worldwide Forums | Help | Site Map

Listbox Binding

OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 361
#1: Jul 9 '09
Hi
I have filled a listbox with a column of information from my sql database

Expand|Select|Wrap|Line Numbers
  1. Private Sub GetClients()
  2.         Dim sqlCom As SqlCommand = New SqlCommand("select emailaddress from register where paymentreceived = 'No'", sqlCon)
  3.         sqlCon.Open()
  4.         sqlAdapter = New SqlDataAdapter(sqlCom)
  5.         sqlAdapter.Fill(sqlDS, "register")
  6.  
  7.  
  8.         dr = sqlCom.ExecuteReader
  9.  
  10.         If dr.HasRows Then
  11.             For Each rec As Common.DbDataRecord In dr
  12.                 alRows.Add(rec)
  13.             Next
  14.             ListBox1.DataSource = alRows
  15.             ListBox1.DisplayMember = "emailaddress"
  16.  
  17.         End If
  18.         sqlCon.Close()
  19.     End Sub
But now when i try to loop through the rows of the listbox

Expand|Select|Wrap|Line Numbers
  1.  Dim i As Integer
  2.         For i = 0 To ListBox1.Items.Count - 1
  3.             MsgBox(ListBox1.Items(i))
  4.         Next
i get an error

conversion from type 'DataRecordInternal' to type 'String' is not valid

is there a better way to get the values... ?

OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 361
#2: Jul 9 '09

re: Listbox Binding


Corrected the error.
Expand|Select|Wrap|Line Numbers
  1. For Each row In sqlTable.Rows
  2.              row("emailAddress")
  3. Next
Reply


Similar Visual Basic .NET bytes