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. .NET (Core and Framework)
  4. How to Show Specific Records in listview

How to Show Specific Records in listview

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasetutorialsql-serversysadminhelp
4 Posts 2 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.
  • A Offline
    A Offline
    akosidandan
    wrote on last edited by
    #1

    Hello experts, I would like to ask if how can I show some specific records only in my listview coming from my database table.My Database is Sql Server 2005 and I am using vb 2008 as the programming language. Scenerio: BorrowTable ID | Last Name | 1 | mrDan 1 | mrDan 2 | mrsDan 2 | mrsDan I have a table in my database with name BorrowTable as shown above for example, my problem is I would like to show the transaction records of people in table.To be more precise bec I cant so much explain my problem I want to display it like this way in my listview ID | Last Name | 1 | mrDan 2 | mrsDan Below here is the code, its working but it just show all the records I have tried "group by" as select query to my sqlDataAdapter but it's not working.

    Public Sub LoadListViewReturn(ByVal lvReturnList As ListView, ByVal con As SqlConnection)
    Try
    If con.State = ConnectionState.Open Then
    con.Close()
    End If

            Dim dt As New DataTable
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            Dim da As New SqlDataAdapter
    
            con.Open()
            da = New SqlDataAdapter("Select \* from BorrowTransactionTable ", con)
            da.Fill(dt)
    
            For Each r As DataRow In dt.Rows
                lvReturnList.Items.Add(r("txtTransactionID"))
                lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtLastName"))
                lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtFirstName"))
                lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtMI"))
                lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtPosition"))
    
            Next
    
    
    
            con.Close()
    
        Catch ex As Exception
            MsgBox(ex.ToString)
            con.Close()
        End Try
    End Sub
    

    Any comments and suggestions are so much appreciated. :) Thanks, Dan

    L 1 Reply Last reply
    0
    • A akosidandan

      Hello experts, I would like to ask if how can I show some specific records only in my listview coming from my database table.My Database is Sql Server 2005 and I am using vb 2008 as the programming language. Scenerio: BorrowTable ID | Last Name | 1 | mrDan 1 | mrDan 2 | mrsDan 2 | mrsDan I have a table in my database with name BorrowTable as shown above for example, my problem is I would like to show the transaction records of people in table.To be more precise bec I cant so much explain my problem I want to display it like this way in my listview ID | Last Name | 1 | mrDan 2 | mrsDan Below here is the code, its working but it just show all the records I have tried "group by" as select query to my sqlDataAdapter but it's not working.

      Public Sub LoadListViewReturn(ByVal lvReturnList As ListView, ByVal con As SqlConnection)
      Try
      If con.State = ConnectionState.Open Then
      con.Close()
      End If

              Dim dt As New DataTable
              Dim ds As New DataSet
              ds.Tables.Add(dt)
              Dim da As New SqlDataAdapter
      
              con.Open()
              da = New SqlDataAdapter("Select \* from BorrowTransactionTable ", con)
              da.Fill(dt)
      
              For Each r As DataRow In dt.Rows
                  lvReturnList.Items.Add(r("txtTransactionID"))
                  lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtLastName"))
                  lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtFirstName"))
                  lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtMI"))
                  lvReturnList.Items(lvReturnList.Items.Count - 1).SubItems.Add(r("txtPosition"))
      
              Next
      
      
      
              con.Close()
      
          Catch ex As Exception
              MsgBox(ex.ToString)
              con.Close()
          End Try
      End Sub
      

      Any comments and suggestions are so much appreciated. :) Thanks, Dan

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      So you want the DISTINCT[^] keyword. You'd better replace the asterisk by the actual list of fields you want returned then, and specify which of those MUST be distinct. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      A 1 Reply Last reply
      0
      • L Luc Pattyn

        So you want the DISTINCT[^] keyword. You'd better replace the asterisk by the actual list of fields you want returned then, and specify which of those MUST be distinct. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        A Offline
        A Offline
        akosidandan
        wrote on last edited by
        #3

        Hello, Thank you so much this is really the answer I was looking for :) Thanks also the link it was super helpfull.Now I can finish the System I am doing, I am stuck in that part due to filtering my listview. Thank so much, Dan

        L 1 Reply Last reply
        0
        • A akosidandan

          Hello, Thank you so much this is really the answer I was looking for :) Thanks also the link it was super helpfull.Now I can finish the System I am doing, I am stuck in that part due to filtering my listview. Thank so much, Dan

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          You're welcome. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          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