473,748 Members | 4,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populating a ListView from an Access Database

2 New Member
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("BirthD ate").Value
Dim DateDifference As Integer = (DateDiff(DateI nterval.DayOfYe ar, date2, date1) \ 30 \ 12)

Names = ""
i = 0

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

Do While Not .EOF

If StrComp(Trim(.F ields(StaffCode ).Value), Trim(cboStaffCo de.Text))=0 Then
f = ListView.Items( i)
ReDim Arr6(i)
Arr6(i) = .Bookmark

Names = .Fields("SurNam e").Value & " " & .Fields("FirstN ame").Value & " " & .Fields("OtherN ames").Value

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

If IsDate(.Fields( "BirthDate").Va lue) 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.ListView Item.ListViewSu bItem'"

(b) f.SubItems(5) = DateDifference - "Value of type 'Integer' cannot be converted to 'System.Windows .Forms.ListView Item.ListViewSu bItem'"

(c) f.SubItems(5) = "" - "Value of type 'String' cannot be converted to 'System.Windows .Forms.ListView Item.ListViewSu bItem'"

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

Patrick
Sep 5 '06 #1
1 4927
sainin
13 New Member
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
1627
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 success. I have even purchased a couple of books on vb.net and still do not have it working. I would like to see some example code that will connect to an Access database and populate a listview box with an autonumber field and a couple of text...
0
1385
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 datetime data type. I get a narrowing conversion error when I attempt to add this column to list view, my syntax is cmdSearchResult = New SqlCommand(strHitList, cn) cmdSearchResult.CommandTimeout = 15 cmdSearchResult.CommandType =...
3
1231
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, it would just sit and consume 100% CPU for aslong as I could be bothered to wait before I pskill's the app. Anyway I was playing and found that even the code below takes a matter of minutes to populate the control: ...
10
1702
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 the following syntax but keep getting the error "Specified cast is not valid". I don't know what's causing this ? Can anybody help ? For Each Item As ListViewItem In frmRepParams.lstAnalysis.SelectedItems If Len(strAnalysis) = 0 Then
7
15002
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 MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
0
1002
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 from this listview to the second listview various ways. What I need help with is I would like to keep the items in the first listview in the same order. As the code is now when an item is moved back to the first listview it goes to the bottom. I...
1
1539
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 (20,000)..... In other languages, when faced with this problem, you can run a query and link it to a datasource and link the datasource to a table. You can then set an option called packetrecords to 20. If your grid has 40 rows, then as it populates...
0
1701
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 SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which...
10
4049
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) then How would you accomplish this using a ListView ?
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.