Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ListView

ListView

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    momooomooomomo
    wrote on last edited by
    #1

    Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader() Try While dtrReader.Read() lstViewBuyers.Items.Add(dtrReader(1)) End While Finally dtrReader.Close() End Try this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview... How can i display the whole record in the sql database to using listview control? pls help

    nothing is impossible.....

    C S J L 4 Replies Last reply
    0
    • M momooomooomomo

      Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader() Try While dtrReader.Read() lstViewBuyers.Items.Add(dtrReader(1)) End While Finally dtrReader.Close() End Try this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview... How can i display the whole record in the sql database to using listview control? pls help

      nothing is impossible.....

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      By using a string builder to build a string out of the data in the row, and then adding that. (1) is returning the second column, you can access them by name or index ( name is more self documenting ), you can build the string any way you like.  There's no way to make the string build itself.

      Christian Graus - C++ MVP

      1 Reply Last reply
      0
      • M momooomooomomo

        Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader() Try While dtrReader.Read() lstViewBuyers.Items.Add(dtrReader(1)) End While Finally dtrReader.Close() End Try this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview... How can i display the whole record in the sql database to using listview control? pls help

        nothing is impossible.....

        S Offline
        S Offline
        sitt
        wrote on last edited by
        #3

        one way but not a good way is concatinate all of your field together that the query result is become to 1 field e.g. sql --> "select f1 + ' ' + f2 + ' ' + f3 + ' ' + f4 from TableName" ' ' is white space, f1 to f4 is field name result --> "aaa aaa aaa aaa" "bbb bbb bbb bbb" "cccc ccc cc ccccc" the output format is not order in column but it's ok if the data is name and surname :-D

        1 Reply Last reply
        0
        • M momooomooomomo

          Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader() Try While dtrReader.Read() lstViewBuyers.Items.Add(dtrReader(1)) End While Finally dtrReader.Close() End Try this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview... How can i display the whole record in the sql database to using listview control? pls help

          nothing is impossible.....

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          Hi, I have solved this problem simply as follows: lstViewBuyers.Items.Add(dtrReader(1) & "|" & dtrReader(2)) I.e. you just concatenate all the fields from the record into a string with a divider between the values. Afterward, if you want to use any part of the record, selected from the listview, you just itirate through the string. The | character (ofcourse you can use any other character or string) serves as the divider. Something like this: Dim divider As String = "|" Dim cut As Integer Dim TheBitYouNeed As String cut = TheBitYouNeed.IndexOf(divider) TheBitYouNeed= Mid(TheBitYouNeed, 1, cut) Hope this helps you, Johan

          1 Reply Last reply
          0
          • M momooomooomomo

            Dim dtrReader As SqlDataReader = cmdCommand.ExecuteReader() Try While dtrReader.Read() lstViewBuyers.Items.Add(dtrReader(1)) End While Finally dtrReader.Close() End Try this is how i display one field from the database to the listview... but my problem is when i come to display one row/record from the database to the listview... How can i display the whole record in the sql database to using listview control? pls help

            nothing is impossible.....

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Hey, another way of doing this if you don't know the amount of columns in the table you are getting would be: Try While dtrReader.Read() Dim lvItem As New ListViewItem(dtrReader(0)) For i As Integer = 1 To dtrReader.FieldCount - 1 lvItem.SubItems.Add(dtrReader(i)) Next lstViewBuyers.Items.Add(lvItem) End While Finally dtrReader.Close() End Try Bsically the same thing, but since the data reader has field information on it, we just use that and create the sub items from the datareader starting at the 1 position. Have you thought of using a bindable list view? You may want to check to see if nulls are coming back though, you may get exceptions when you get data from a datareader that has null values and try to add it to a list view item like this.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups