Results 1 to 6 of 6

Thread: help with fuctions [RESOLVED]

Hybrid View

  1. #1
    Member scavenger's Avatar
    Join Date
    Aug 2004
    Location
    Nowhere
    Posts
    42
    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:
    1. Public Function FillListView(ByRef lst As ListView) As Boolean
    2.         Dim SQLComm As New SqlCommand()
    3.         Dim SQLConn As New SqlConnection("<your connection string here>")
    4.         Dim DatReader As SqlDataReader
    5.         Dim i, index As Integer
    6.         index = 0
    7.         SQLComm.CommandText = "<your command text here>"
    8.         SQLConn.Open()
    9.         SQLComm.Connection = SQLConn
    10.         With SQLComm
    11.             .Parameters.Add("<Parameter Name here>")
    12.             'You can add as many parameters as you desire. But it must match the parameters in your commandtext
    13.             DatReader = .ExecuteReader
    14.             While DatReader.Read
    15.                 lst.Items.Add(IsDataNull(DatReader, 0)) 'First Item
    16.                 if DatReader.FieldCount > 0 then
    17.  
    18.                 For i = 1 To DatReader.FieldCount - 1 'If your commandtext has many rows to fetch
    19.                     ' we deducted 1 to the fieldcount becoz it is base-1 not zero-based
    20.                     ' we started at 1 becoz we already fetch the first data
    21.                     lst.Items(index).SubItems(i).Text = IsDataNull(DatReader, i)
    22.                 Next
    23.                 End If
    24.                 index += 1
    25.                 'move on the next fetch
    26.             End While
    27.             DatReader.Close()
    28.         End With
    29.         If lst.Items.Count = 0 Then
    30.             Return False
    31.         Else
    32.             Return True
    33.         End If
    34.     End Function
    35.  
    36.     Private Function IsDataNull(ByVal DataReader As SqlDataReader, ByVal index As Integer) As String
    37.         If IsDBNull(DataReader.GetValue(index)) Then
    38.             Return " "
    39.             'since listviewitems does not allow nulls to be displayed only strings
    40.         Else
    41.             Return DataReader.GetValue(index)
    42.             'just return the original value
    43.         End If
    44.     End Function




    Hope this helps...if not...my apologies....
    Last edited by scavenger; Aug 24th, 2004 at 08:44 PM.
    "It takes great courage to survive"
    -kenshin himura

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