Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
https://stackoverflow.com/questions/18584707/how-to-add-items-in-a-datatable-to-a-listview Sorry to use a link as explanation but this link tells everything I wanted to say. Start with a SqlConnection con = new SqlConnection("connectionstring"); in which your connectionstring to the database is located. Than add a "sqladapter", which is a container of tables. Here you can put you sqlcommand to get the data. Now the data is in the container SqlDataAdapter ada = new SqlDataAdapter("select * from MasterLocation", con); Create a datatable and fill the datatable with data DataTable dt = new DataTable(); ada.Fill(dt); Use a loop to fill you listview for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; ListViewItem listitem =new ListViewItem(dr["pk_Location_ID"].ToString()); listitem.SubItems.Add(dr["var_Location_Name"].ToString()); listitem.SubItems.Add(dr["fk_int_District_ID"].ToString()); listitem.SubItems.Add(dr["fk_int_Company_ID"].ToString()); listView1.Items.Add(listitem); } Another way could be to bind the listview to the datatable using a bind-object. The you use the table name and field name to define what you want to show in the listview. Do you use winform or wpf
2nd Jun 2017, 6:43 PM
sneeze
sneeze - avatar