Results 1 to 2 of 2

Thread: Data Access and vb.net

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954

    Data Access and vb.net

    I am trying to populate a list view when a user choses a select from a combo box. It goves me nothing when it runs, the list view is blank. The code is below (pos is the selection from the list box which are different table names).

    VB Code:
    1. Private Sub getPlayers(ByVal pos As String)
    2.         Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\db\dbff.mdb"
    3.         Dim myConnection As OleDbConnection = New OleDbConnection()
    4.         myConnection.ConnectionString = connString
    5.  
    6.         ' create a data adapter
    7.         Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from " & pos, myConnection)
    8.         Dim ds As DataSet = New DataSet()
    9.         ' fill dataset
    10.         da.Fill(ds, pos)
    11.         Dim dt As DataTable = ds.Tables(pos)
    12.         Dim row As DataRow
    13.         ListView1.Clear()
    14.         ListView1.View = View.Details
    15.         ' Allow the user to edit item text.
    16.         ListView1.LabelEdit = True
    17.         '' Allow the user to rearrange columns.
    18.         ListView1.AllowColumnReorder = True
    19.         '' Display check boxes.
    20.         'ListView1.CheckBoxes = True
    21.         '' Select the item and subitems when selection is made.
    22.         ListView1.FullRowSelect = True
    23.         ' Display grid lines.
    24.         ListView1.GridLines = True
    25.         ' Sort the items in the list in ascending order.
    26.  
    27.         ListView1.Columns.Add("Player ID", -2, HorizontalAlignment.Left)
    28.         ListView1.Columns.Add("Name", -2, HorizontalAlignment.Left)
    29.         ListView1.Columns.Add("Price", -2, HorizontalAlignment.Left)
    30.  
    31.  
    32.         ListView1.BeginUpdate()
    33.         For Each row In dt.Rows
    34.             Dim itmX As ListViewItem
    35.             itmX = ListView1.Items.Add(row("ID"))
    36.             itmX.SubItems.Add(row("Name"))
    37.             itmX.SubItems.Add(row("Price"))
    38.             '    colP.Add(row("ID") & row("Name") & ":" & row("Price") & ":" & row("Team") & ":" & row("GamesPlayed") & ":" & row("Completions") & ":" & row("Attempts") & ":" & row("PYards") & ":" & row("TD"), row("id"))
    39.         Next
    40.         ListView1.EndUpdate()
    41.  
    42.     End Sub

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Hmm it looks like it should be right, maybe try using this instead on the For Each:
    VB Code:
    1. For Each row In ds.Tables(0).Rows

    Or set some breakpoints and see what part isn't doing it's job.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width