Results 1 to 5 of 5

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

  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

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    243

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

    any ideas???

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

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

    Your link goes to the site map? Also, whats your error and which line of code?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    243

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

    My error occurs on the strtest = IIf(myData.IsDBNull(0), "", myData.GetString(0)) line.

    I checked the myData.IsDBNull(0) value when I stepped through the debugger. It returns "false", so that is correct. And the value for myData.GetString(0) is also correct. But when I run the code I get an error.

    Error:
    Specified cast is not valid.
    Last edited by zombie_man23; Aug 22nd, 2005 at 01:14 PM.

  5. #5
    Fanatic Member jcavard's Avatar
    Join Date
    Jul 2005
    Location
    Quebec, CANADA
    Posts
    534

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

    I have encountered the same issue, I got code from codeguru, that doesnt work for listview filling...

    VB Code:
    1. dim lstStuff as listItem = new listViewItem() ' <<----- this first line gives me an error, saying listitem aint declared....
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

    accoustic emo-rock band: a tailormade fable

    Visual Studio 2003 / Framework 1.1

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