Results 1 to 5 of 5

Thread: Web Example doesn't work / dataset to listview

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    243

    Web Example doesn't work / dataset to listview

    Here is the link to the page that I took the example from.
    http://www.codeguru.com/vb/controls...icle.php/c3979/
    I am using the last code example at the bottom of the page.

    Here is the code I have:

    VB Code:
    1. Public Class clsLoadListView
    2. Dim myFM As New frmMain
    3. Dim ds As New DataSet
    4. Dim myData As OdbcDataReader
    5.  
    6. Public Sub loadSelections(ByVal SelectBy As String)
    7. Dim building As Integer
    8. Dim sql As String
    9. Dim lvwColumn As ColumnHeader
    10. Dim itmListItem As ListViewItem = New ListViewItem
    11. Dim strtest As String
    12. Dim shtCntr As Short
    13.  
    14. building = 11
    15.  
    16. '----fill in the field list
    17. Try
    18. myFM.dbconn.Open()
    19.  
    20. Select Case SelectBy
    21. Case "Students"
    22.  
    23. sql = "select studentid, studentname from reg where studentid = 18197 and building = " & building
    24. myFM.cmd = New OdbcCommand(sql, myFM.dbconn)
    25. myFM.cmd.CommandType = CommandType.Text
    26.  
    27. myData = myFM.cmd.ExecuteReader
    28.  
    29. myFM.lvwFields.Clear()
    30. For shtCntr = 0 To myData.FieldCount() - 1
    31. lvwColumn = New ColumnHeader
    32. lvwColumn.Text = myData.GetName(shtCntr)
    33. myFM.lvwFields.Columns.Add(lvwColumn)
    34. Next
    35.  
    36. Do While myData.Read
    37. itmListItem = New ListViewItem
    38. itmListItem.Text = myData(0)
    39.  
    40. For shtCntr = 1 To myData.FieldCount() - 1
    41. If myData.IsDBNull(shtCntr) Then
    42. itmListItem.SubItems.Add("")
    43. Else
    44. itmListItem.SubItems.Add(myData.GetString(shtCntr).Trim)
    45. End If
    46. Next shtCntr
    47.  
    48. myFM.lvwFields.Items.Add(itmListItem)
    49. Loop
    50.  
    51. End Select
    52.  
    53. Catch ex As Exception
    54. MessageBox.Show("Error Reading Data. " & ex.Message)
    55. Finally
    56. myFM.dbconn.Close()
    57. lvwColumn = Nothing
    58. End Try
    59. End Sub
    Last edited by RobDog888; Aug 22nd, 2005 at 11:24 AM. Reason: Added vbcode tags

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