我想从sql中读取并插入到datagridview中。但是,sql中的列存在多次只能在datagridview中插入一次。
SqlDataAdapter sda = new SqlDataAdapter("select * from customerbase ", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.Rows.Clear();
foreach (DataRow item in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = item[0].ToString();
dataGridView1.Rows[n].Cells[0].Value = item[1].ToString();
使用此代码它会带来所有sql记录。我想阻止相同的记录。