データベースには Microsoft が提供するサンプルデータベース Northwind の Employees テーブルを使ってみます。以下のような構造で、質問者さんの使っているものに近いのでは?
コードは以下のようになります。以下のコードの Employee クラスが List<T> の T になります。SQL Server からデータを取得して、それから List<Employee> オブジェクトを作成し、DataGridView に BindingSource 経由でバインドしています。foreach は書く必要はありません。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form7 : Form
{
private DataGridView dataGridView1;
private BindingSource bindingSource1;
public Form7()
{
InitializeComponent();
this.dataGridView1 = new DataGridView();
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.bindingSource1 = new BindingSource();
this.dataGridView1.DataSource = this.bindingSource1;
this.Controls.Add(this.dataGridView1);
this.bindingSource1.DataSource = GetEmployeeList();
}
private List<Employee> GetEmployeeList()
{
string connString = @"Data Source=(local)\sqlexpress;Initial Catalog=NORTHWIND;Integrated Security=True";
string query = "SELECT [EmployeeID],[LastName],[FirstName],[Address] FROM [Employees]";
List<Employee> list = new List<Employee>();
using (SqlConnection connection = new SqlConnection(connString))
{
using (SqlCommand command = new SqlCommand(query, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while(reader.Read())
{
Employee emp = new Employee
{
Id = reader.GetInt32(0),
Name = reader.GetString(2) + " " + reader.GetString(1),
Address = reader.GetString(3)
};
list.Add(emp);
}
}
}
}
return list;
}
}
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
}