Baba mba Baba mba - 1 year ago 75
C# Question

Why do i get System.Data.DataRow?

I wanna show my rows in a listbox and the table names but when i run my code it says System.Data.DataRow can someone help me

my code is

foreach (object SelectedValue in ListEmployees.SelectedItems)
using (connection = new SqlConnection(connectionstring))
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM " + selectedCel, connection))
DataTable employees = new DataTable();

for (int i = 0; i < employees.Rows.Count; i++)
DataRow dr = employees.Rows[i];
ListViewItem itm = ListViewItem(dr.ToString());


Answer Source

DataRow.ToString() just prints out the full type name.

Presuming you want to show the first column:

ListViewItem itm = new ListViewItem(dr.Field<string>(0));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download