.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2003, 08:34 PM
slconsult slconsult is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Essex, ON
Posts: 18 slconsult User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 35 sec
Reputation Power: 0
populating a listview from a database

I am trying to populate a ListView called ListView1 with data from my ttimeoff table. I have included some code. The summary click event is to bring up all of the days off from ttimeoff for the name selected in the combobox1. I got the listview1 form load event right because all of the proper columns show up. I can't seem to make any head way populating it. I just need to know if I am on the right track or if anyone can point me in the right direction.

Private Sub ListView1Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'add columns

ListView1.Columns.Add("USERID", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("SICK", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("LOA", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("SUSP", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("PPH", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("PAA", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("BER", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("AWOL", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("VAC", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("EMERG", 70, HorizontalAlignment.Center)
ListView1.Columns.Add("MATERN", 70, HorizontalAlignment.Center)


End Sub

Private Sub btnSummary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSummary.Click
Dim userid As String
Dim datesick As Date
Dim datebereave As Date
Dim datesusp As Date
Dim datemat As Date
Dim dateloa As Date
Dim datepph As Date
Dim datepaa As Date
Dim dateemerg As Date
Dim datevac As Date
Dim dateabsent As Date

Dim Item As String
Dim ListViewItem As ListViewItem

SQL = "Select * FROM ttimeoff WHERE USERID = '" & Trim(UCase("" & ComboBox1.SelectedItem())) & "'"

Try
ListView1.Items.Clear()
SQL = "Select * FROM ttimeoff WHERE USERID = '" & Trim(UCase("" & ComboBox1.SelectedItem())) & "'"
For Each Item In ComboBox1.Items
ListViewItem = New ListViewItem(Item.ToString)
ListViewItem.SubItems.Add(Rs.Fields(userid).Value)
ListViewItem.SubItems.Add(Rs.Fields(datesick).Value)
ListViewItem.SubItems.Add(Rs.Fields(datebereave).Value)
ListViewItem.SubItems.Add(Rs.Fields(datesusp).Value)
ListViewItem.SubItems.Add(Rs.Fields(datemat).Value)
ListViewItem.SubItems.Add(Rs.Fields(dateloa).Value)
ListViewItem.SubItems.Add(Rs.Fields(datepph).Value)
ListViewItem.SubItems.Add(Rs.Fields(datepaa).Value)
ListViewItem.SubItems.Add(Rs.Fields(dateemerg).Value)
ListViewItem.SubItems.Add(Rs.Fields(datevac).Value)
ListViewItem.SubItems.Add(Rs.Fields(dateabsent).Value)
ListView1.Items.Add(ListViewItem)
Next

Catch ES As Exception
MsgBox(ES.Message)
End Try
End Sub

Thank you,
SLCONSULT

Reply With Quote
  #2  
Old September 16th, 2003, 09:37 AM
Watever Watever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 486 Watever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 20 sec
Reputation Power: 5
it's look good IMO

but I just don't understand where is your problem and your code doesn't do that it is suppose to do.
you want to make a header or something like that ?

Reply With Quote
  #3  
Old September 16th, 2003, 12:31 PM
slconsult slconsult is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Essex, ON
Posts: 18 slconsult User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 5 m 35 sec
Reputation Power: 0
populating a database

Thanks for your reply. The problem lies that the event is not drawing the data from my table ttimeoff. The listview is simply listing all the members of my combobox1 and the date of 1/1/0000 in the columns. I can't figure out how to get it to populate from my database. I am using SQL as my database.

thanks again,

Reply With Quote
  #4  
Old September 16th, 2003, 12:42 PM
Watever Watever is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 486 Watever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 20 sec
Reputation Power: 5
Has I can see you do not connect yourself to your database. I suggest you use ADO for it cause in .Net the dao is kinda slow and it doesn't automaticly save the modifications.

It's kinda hard to explain exaclty how it's work. I used it a lof in vb6 but in .net things are a little bit different and I am still learning about it.

I suggest you search about it on www.planetsourcecode.com and www.google.com/microsoft
those 2 website helped me when I got some problems with the code I am correcting right now.

Reply With Quote
  #5  
Old September 16th, 2003, 12:47 PM
Wingman Wingman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Bavaria, Germany
Posts: 140 Wingman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 40 m 41 sec
Reputation Power: 6
Hehe, nice little bug :-)

Code:
Dim userid As String 
Dim datesick As Date 
Dim datebereave As Date 
...
ListViewItem.SubItems.Add(Rs.Fields(userid).Value) 
ListViewItem.SubItems.Add(Rs.Fields(datesick).Value) 
ListViewItem.SubItems.Add(Rs.Fields(datebereave).Value) 
ListViewItem.SubItems.Add(Rs.Fields(datesusp).Value) 
ListViewItem.SubItems.Add(Rs.Fields(datemat).Value) 
ListViewItem.SubItems.Add(Rs.Fields(dateloa).Value) 


This *can't* work since you never initialize those variables since the above "ListViewItem.SubItems..." statements evaluated always look like this:

Code:
 
' "ListViewItem.SubItems.Add(Rs.Fields(userid).Value)" becomes
ListViewItem.SubItems.Add(Rs.Fields("").Value)

' "ListViewItem.SubItems.Add(Rs.Fields(datesick).Value)" becomes 
ListViewItem.SubItems.Add(Rs.Fields("").Value)

' and so on...


I guess you meant:

Code:
ListViewItem.SubItems.Add(Rs.Fields("userid").Value) 
ListViewItem.SubItems.Add(Rs.Fields("datesick").Value) 
ListViewItem.SubItems.Add(Rs.Fields("datebereave").Value) 
ListViewItem.SubItems.Add(Rs.Fields("datesusp").Value) 

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > populating a listview from a database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway