Sql to datagridView防止相同的记录

时间:2016-04-16 19:40:59

标签: c# sql-server

我想从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记录。我想阻止相同的记录。

0 个答案:

没有答案