如何通过使用数据集从数据库中获取数据而无需重复(不重复) [英] How to get data from DataBase without repeation( distinct) by using dataset

查看:124
本文介绍了如何通过使用数据集从数据库中获取数据而无需重复(不重复)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过使用数据集从数据库中获取数据而无需重复(不重复)
它成功了

How to get data from DataBase without repeation( distinct) by using dataset
It successed by this

ConString = WebConfigurationManager.ConnectionStrings["KutubDBConnectionString"].ConnectionString;
       Conn = new SqlConnection(ConString);
       CMD = new SqlCommand("SelectYearsRange", Conn);
       CMD.CommandType = CommandType.StoredProcedure;

       Conn.Open();

       Da = new SqlDataAdapter(CMD);
       DataTable dt = new DataTable();

       Da.Fill(dt);
       return dt;



但我想这样做:




But I want to do it like this:


KutubDataSetTableAdapters.BooksTableAdapter Bta = new KutubDataSetTableAdapters.BooksTableAdapter();
   KutubDataSet Kds = new KutubDataSet();
   DataView SearchView;

      Bta.Fill(Kds.Books);

      SearchView = new DataView(Kds.Tables["Books"]);

      SearchView.RowFilter = "??";




我应该在SearchView.RowFilter中写什么?!




What should I write in SearchView.RowFilter ?!

推荐答案

,如果您可以更改存储过程或添加新的存储过程以返回不同的记录,则是这种情况下的最佳解决方案.但是如果不能这样做,请检查如何在数据表中选择不同的行并将其存储到数组中. [ ^ ]
DataView.ToTable方法的文档(字符串,布尔值,字符串[]) [ ^ ]
if you can change the stored procedure or add new stored procedure to return distinct record is the best solution in this case. but if you can''t do that, check How to select distinct rows in a datatable and store into an array.[^]
and the documentation of DataView.ToTable Method (String, Boolean, String[])[^]


这篇关于如何通过使用数据集从数据库中获取数据而无需重复(不重复)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆