title: How to add items in a datatable to a listview?
body: <p>I am currently developing a C# Windows Form Application.</p>
  
  <p>Now I am trying to use a SQL Command to retrieve information from the database to fill in the information that I need to have in my Application.</p>
  
  <p>A sample query would be "select * from Location"</p>
  
  <p>In the Location table there would be variables like  locationId, LocationName , districId etc etc.
  I used the following code</p>
  
  <pre><code>private void button1_Click(object sender, EventArgs e)
  {
      SqlConnection con = new SqlConnection("connectionstring");
      SqlDataAdapter ada = new SqlDataAdapter("select * from MasterLocation", con);
      DataTable dt = new DataTable();
      ada.Fill(dt);
  
      for (int i = 0; i &lt; 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);
      } 
  </code></pre>
  
  <p>The output is:</p>
  
  <p><img src="https://i.stack.imgur.com/52kTu.png" alt="like this."></p>
  
  <p>but it should be like this:</p>
  
  <p><img src="https://i.stack.imgur.com/bGXSE.png" alt="sql output"> </p>