I am trying to populate a listview or a listbox from database using C#. I am using datatable to grab data. I am using this code below. But listview or the listbox is populating something like "System.Data.DataRow"
text. Where I have something else in my database. Pls Help
query = "select itemtag from tbl_inventory order by itemtag";
DataTable dt = con.DataTable(query);
int count = dt.Rows.Count;
if (count >0)
{
//listView1.Items.Clear();
listBox1.Items.Clear();
for (int i = 0; i < count; i++)
{
//listView1.Items.Add(dt);
listBox1.Items.Add(dt.Rows[i].ToString());
}
}
,where I have something else in my database
Any help?
If your using a listbox then directly use the DATASOURCE property...
ListBox1.DataSource
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With