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
Re: Web Example doesn't work / dataset to listview
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?
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.
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....