C# 使用asp c仅显示中继器控件中的唯一列#
我正在尝试从数据库绑定repeater控件。但我需要将repeater绑定到唯一列。 例如 到C# 使用asp c仅显示中继器控件中的唯一列#,c#,asp.net,.net,sql-server,C#,Asp.net,.net,Sql Server,我正在尝试从数据库绑定repeater控件。但我需要将repeater绑定到唯一列。 例如 到 孟买、哈里亚纳、果阿 我的代码如下 SqlConnection con3 = new SqlConnection("myconnection"); string strcon = "select * from indiapincodes where statename =@statename"; cmd = new SqlCommand(strcon, con3);
孟买、哈里亚纳、果阿
我的代码如下
SqlConnection con3 = new SqlConnection("myconnection");
string strcon = "select * from indiapincodes where statename =@statename";
cmd = new SqlCommand(strcon, con3);
da = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@statename", erouting);
ds = new DataSet();
da.Fill(ds, "emp");
Repeater1.DataSource = ds;
Repeater1.DataBind();
con3.Close();
con3.Dispose();
上面的代码运行良好,但我想知道如何过滤具有唯一值的列并填写repeater。提前谢谢。您能显示查询的输出吗?输出是“孟买,哈里亚纳,果阿,哈里亚纳,孟买”,但我想删除重复值,例如孟买和哈里亚纳显示2次是那些列名还是字符串数据或行?它是什么?更好的方法是在将数据绑定到中继器控件之前过滤数据。使用distinct关键字筛选重复数据您在中继器中只显示一列值?如果是,则应在Sql查询中使用DISTINCT。将在where子句中为该列的匹配条件返回唯一值。
string strcon = "SELECT DISTINCT columnname from indiapincodes WHERE statename=@statename";
string strcon = "SELECT DISTINCT columnname from indiapincodes WHERE statename=@statename";