Yellow!
I would like to suggest this code.
If you want Andy, you can examine it...
Hope this one helps.... I used this one in my code.
ahehe...
VB Code:
Public Function FillListView(ByRef lst As ListView) As Boolean Dim SQLComm As New SqlCommand() Dim SQLConn As New SqlConnection("<your connection string here>") Dim DatReader As SqlDataReader Dim i, index As Integer index = 0 SQLComm.CommandText = "<your command text here>" SQLConn.Open() SQLComm.Connection = SQLConn With SQLComm .Parameters.Add("<Parameter Name here>") 'You can add as many parameters as you desire. But it must match the parameters in your commandtext DatReader = .ExecuteReader While DatReader.Read lst.Items.Add(IsDataNull(DatReader, 0)) 'First Item if DatReader.FieldCount > 0 then For i = 1 To DatReader.FieldCount - 1 'If your commandtext has many rows to fetch ' we deducted 1 to the fieldcount becoz it is base-1 not zero-based ' we started at 1 becoz we already fetch the first data lst.Items(index).SubItems(i).Text = IsDataNull(DatReader, i) Next End If index += 1 'move on the next fetch End While DatReader.Close() End With If lst.Items.Count = 0 Then Return False Else Return True End If End Function Private Function IsDataNull(ByVal DataReader As SqlDataReader, ByVal index As Integer) As String If IsDBNull(DataReader.GetValue(index)) Then Return " " 'since listviewitems does not allow nulls to be displayed only strings Else Return DataReader.GetValue(index) 'just return the original value End If End Function
Hope this helps...if not...my apologies....
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()




Reply With Quote