Handling datatables and datarows

lucasite

Member
Joined
Dec 1, 2004
Messages
8
Programming Experience
3-5
Please help, Im stuck and am going crazy with this simple problem.

My code runs a function from a class and returns a dataset of records from the sqlserver.

All i want to do is work through the dataset and for each record, insert it into a listview.

Please can anyone spot the problem with this code:

Dim ds As New DataSet()
Dim dt As New DataTable()
Dim dr As DataRow()

ds = m_BO.admin_GetUsers()
dt = ds.Tables("Users")

For Each dr In dt.Rows
ListView1.Items.Add(Convert.ToString(dr.GetValue(2)))
Next

The error occurs on the For each line:
An unhandled exception of type 'System.InvalidCastException' occurred
Additional information: Specified cast is not valid.

There is definitely data there, I am sure of that at least.

Please please help before I go crazy :confused:
 
Top Bottom