Reputation: 29
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();
adapter.Fill(employees);
for (int i = 0; i < employees.Rows.Count; i++)
{
DataRow dr = employees.Rows[i];
ListViewItem itm = ListViewItem(dr.ToString());
listView1.Items.Add(itm);
}
}
}
Upvotes: 1
Views: 5507
Reputation: 460138
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));
i wanna show all columns that are in the table
string[] allColumns = dr.ItemArray.Select(obj => obj.ToString()).ToArray();
ListViewItem itm = new ListViewItem(allColumns);
Upvotes: 3