473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Populating a ListView from an Access Database

Am upgrading an application from VB6 to VB.Net. One of the controls is a ListView that am failing to populate. Am including some of the code for some assistance where I may be going wrong.

Private Sub ShowFielgs()
Dim f As ListViewItem
Dim i As Integer
Dim Names as String
Dim Arr6() As Object

With tbStaffm
Dim date1 As Date = Now
Dim date2 As Date = .Fields("BirthDate").Value
Dim DateDifference As Integer = (DateDiff(DateInterval.DayOfYear, date2, date1) \ 30 \ 12)

Names = ""
i = 0

If .RecordCount > 0 Then
ListView.Items.Clear()
.MoveFirst()

Do While Not .EOF

If StrComp(Trim(.Fields(StaffCode).Value), Trim(cboStaffCode.Text))=0 Then
f = ListView.Items(i)
ReDim Arr6(i)
Arr6(i) = .Bookmark

Names = .Fields("SurName").Value & " " & .Fields("FirstName").Value & " " & .Fields("OtherNames").Value

f.Text = .Fields("RecordCount").Value
f.SubItems(1) = Names

If IsDate(.Fields("BirthDate").Value) Then
f.SubItems(5) = DateDifference
Else
f.SubItems(5) = ""
End If

i = i + 1
End If

When I try to run the application I get errors at:
(a) f.SubItems(1) = Names - "Value of type 'String' cannot be converted to 'System.Windows.Forms.ListViewItem.ListViewSubItem '"

(b) f.SubItems(5) = DateDifference - "Value of type 'Integer' cannot be converted to 'System.Windows.Forms.ListViewItem.ListViewSubItem '"

(c) f.SubItems(5) = "" - "Value of type 'String' cannot be converted to 'System.Windows.Forms.ListViewItem.ListViewSubItem '"

I need help because I ve tried to change to other variable values without success

Patrick
Sep 5 '06 #1
1 4890
sainin
13
Patrick. The error messages are very clear. You are trying to compare a listview item (type is listviewitem) with other types (such as integer, string). .Net is a type-safe environment and wont let you compare different types.

So the way is to read the listview item's value. Convert the value to the type you want to compare (such as datetime, integer, string); use Convert(..., Int32) e.g. And then compare.You would like to catch any exceptions while converting the type.

Hope that helps.
Sep 6 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: MrB | last post by:
I am quite new to vb.net. I have been using VBA for years, but an having problems with populating a listview. I have tried many things, including snippets of code from some news groups with no...
0
by: James | last post by:
I am using an sqldatareader and trying to add items from a sql select statement to a listview control. All columns from sql select statement are added into listview except one column that is a sql...
3
by: Paul Tomlinson | last post by:
All very simple app which loads a log file, parses it and displays the lines in a listview. I was playing about with some largeish files 800K and I noticed that the app would never return control,...
10
by: Robert Zirpolo | last post by:
I have a listview in my application which now enables multiple entries to be selected. I now need to put the value of the selected entries into a string to be used for reporting purposes. I use...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
0
by: thomasp | last post by:
I have a 2 listviews on a windows form in my VB2005 applicaion. The first listview is populated by the columns from a database table when the form opens. The user can move items back and forth...
1
by: Dave Hutchings | last post by:
Hi, My problem is this, I have a search screen which creates a query that performs a search on a large database. The results of this search could, if the user requires, return many many rows...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
10
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever)...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.