How to Show Specific Records in listview
-
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 IfDim 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
-
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 IfDim 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
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.
-
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.
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
-
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
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.