如何在Gridview中检索重复数据条目Usig Asp.Net C# [英] How Do I Retrieve Dplicate Data Entries In A Gridview Usig Asp.Net C#

查看:202
本文介绍了如何在Gridview中检索重复数据条目Usig Asp.Net C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi..i对于如何检索重复的数据条目并在网格视图中显示它们没有任何想法。我正在使用ms access database.and我想显示整行的重复数据条目。

我的数据库表(myd.mdb)包含name,id和branch fields.so请帮助我



thanku

hi..i dont have any idea about how to retrieve duplicate data entries and display them in grid view.I am using ms access database.and i want to display entire rows of duplicate data entries.
my data base table(myd.mdb)contains name,id and branch fields.so pls help me

thanku

推荐答案

这样做的一种方法是,最快的是编写一个查询来获取重复项,例如:

One way to do this is and probably the quickest is to write a query to get duplicates, something like :
select * from table1
  inner join (
    select name,count(*)
    from table1
    group by name
    having count(*) > 1) duplicates on table1.name = duplicates.name



将此查询的结果绑定到gridview。 gridview将显示带有自己'id'的'name'字段的副本。然后你可以像往常一样将'Id'值绑定到gridview控件。


Bind the result of this query to the gridview. The gridview will show the duplicates of 'name' field with their own 'id'. You can then bind 'Id' value as usual to gridview controls.


Quote:

sorry.actually我不是.net的专家,我是新手。请你帮我把它保存在我的代码中。你把它放在我上面提到的编码部分..

sorry.actually i am not expert in .net and i am new to this..could u pls help me to where it is to be kept in my code.can u put it in my above mentioned coding part..




没问题。

首先保存这样的用户条目:



No problem.
First save the user entry like this:

string searchValue = textbox1.Text;



然后在重定向到其他页面时,添加:


Then on redirect to other page, add this:

string queryString = "?searchValue=" + searchValue; //<- Add the query string parameter using '?' - ?[paramaterName]=[value]. If you want to add more than one parameter append '&' and repeat parameter name,value format. e.g. "otherpage.aspx?p1=john&p2=smith".

Response.Redirect("OtherPage.aspx" + queryString);





在'OtherPage.aspx'的页面加载中检索参数:





In page load of 'OtherPage.aspx' retrieve the parameter :

string searchValue = Request.QueryString("searchValue");
// Then send this to your query:
SqlCommand cmd = new SqlCommand("Select * from table where field1 = " + searchValue);
// Or 
cmd.Parameters.Add("@id", OleDbType.Integer).Value = searchValue; 





如果您觉得有帮助,请标记为答案。



If you find this helpful, please mark as answer.


这篇关于如何在Gridview中检索重复数据条目Usig Asp.Net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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