SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=ECMS");
SqlDataAdapter adapter = new SqlDataAdapter("select * from CM_User",con);
DataSet ds = new DataSet();
con.Open();
adapter.Fill(ds,"CM_User");
con.Close();
DataTable dt = new DataTable();
dt = ds.Tables["CM_User"];
for (int n = 0; n < dt.Rows.Count; n++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = dt.Rows[n]["UserID"].ToString();
dataGridView1.Rows[n].Cells[1].Value = dt.Rows[n]["UserName"].ToString();
dataGridView1.Rows[n].Cells[2].Value = dt.Rows[n][2].ToString();
dataGridView1.Rows[n].Cells[3].Value = dt.Rows[n][3].ToString();
dataGridView1.Rows[n].Cells[4].Value = dt.Rows[n][4].ToString();
}