|
-
Aug 18th, 2005, 09:30 AM
#1
Thread Starter
Addicted Member
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:
Public Class clsLoadListView
Dim myFM As New frmMain
Dim ds As New DataSet
Dim myData As OdbcDataReader
Public Sub loadSelections(ByVal SelectBy As String)
Dim building As Integer
Dim sql As String
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem = New ListViewItem
Dim strtest As String
Dim shtCntr As Short
building = 11
'----fill in the field list
Try
myFM.dbconn.Open()
Select Case SelectBy
Case "Students"
sql = "select studentid, studentname from reg where studentid = 18197 and building = " & building
myFM.cmd = New OdbcCommand(sql, myFM.dbconn)
myFM.cmd.CommandType = CommandType.Text
myData = myFM.cmd.ExecuteReader
myFM.lvwFields.Clear()
For shtCntr = 0 To myData.FieldCount() - 1
lvwColumn = New ColumnHeader
lvwColumn.Text = myData.GetName(shtCntr)
myFM.lvwFields.Columns.Add(lvwColumn)
Next
Do While myData.Read
itmListItem = New ListViewItem
itmListItem.Text = myData(0)
For shtCntr = 1 To myData.FieldCount() - 1
If myData.IsDBNull(shtCntr) Then
itmListItem.SubItems.Add("")
Else
itmListItem.SubItems.Add(myData.GetString(shtCntr).Trim)
End If
Next shtCntr
myFM.lvwFields.Items.Add(itmListItem)
Loop
End Select
Catch ex As Exception
MessageBox.Show("Error Reading Data. " & ex.Message)
Finally
myFM.dbconn.Close()
lvwColumn = Nothing
End Try
End Sub
Last edited by RobDog888; Aug 22nd, 2005 at 11:24 AM.
Reason: Added vbcode tags
-
Aug 22nd, 2005, 10:56 AM
#2
Thread Starter
Addicted Member
Re: Web Example doesn't work / dataset to listview
-
Aug 22nd, 2005, 11:24 AM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 22nd, 2005, 11:43 AM
#4
Thread Starter
Addicted Member
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.
-
Aug 30th, 2005, 09:17 AM
#5
Fanatic Member
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:
dim lstStuff as listItem = new listViewItem() ' <<----- this first line gives me an error, saying listitem aint declared....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|