1

Gridview 显示重复的行。我的数据库不包含重复的行。我尝试了 AutoGenerateColumns="false",这不仅删除了重复项,而且还删除了 Gridview 中的所有数据,即不显示任何行。

下面给出的是我的gridview代码

<asp:GridView ID="GridView1" runat="server" 
            style="margin-bottom: 10px; margin-top: 10px;" HorizontalAlign="Center" BackColor="White" 
            BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
            EnableModelValidation="True" GridLines="Horizontal">
            <AlternatingRowStyle BackColor="#F7F7F7" />
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
        </asp:GridView>

下面显示的是我的 aspx.cs 文件中的代码

SqlConnection connection;
SqlDataAdapter adapter;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Z\Documents\Visual Studio 2010\Projects\FF\FF\App_Data\Database1.mdf;Integrated Security = true; User Instance = true");

//*****Show Table Data****
string ss = @"
SELECT person.[account type], 
   person.email, 
   person.name, 
   person.gender, 
   person.dob, 
   person.country, 
   person.city, 
   person.nationality, 
   person.cnic, 
   person.person_id, 
   degree.degreelevel, 
   degree.degreetitle, 
   degree.majorsubject, 
   degree.country         AS Expr1, 
   degree.institution, 
   degree.completionyear, 
   degree.degree_id, 
   degree.person_id       AS Expr2, 
   professional.haveworkexperience, 
   professional.areaofinterest, 
   professional.functionalarea, 
   professional.careerlevel, 
   professional.firstjobstartdate, 
   professional.workexperience, 
   professional.professionalindutry, 
   professional.professional_id, 
   professional.person_id AS Expr3, 
   phone.phonenumber, 
   phone.phone_id, 
   phone.person_id        AS Expr4, 
   recentjob.recentjobtitle, 
   recentjob.jobperiodfromdate, 
   recentjob.jobperiodtodate, 
   recentjob.country      AS Expr5, 
   recentjob.companyname, 
   recentjob.city         AS Expr6, 
   recentjob.job_id, 
   recentjob.person_id    AS Expr7 
FROM   person 
   CROSS JOIN degree 
   CROSS JOIN professional 
   CROSS JOIN phone 
   CROSS JOIN recentjob";

connection.Open();
SqlCommand cmds = new SqlCommand(ss, connection);
adapter = new SqlDataAdapter(cmds);
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
4

1 回答 1

0

我的数据库不包含重复的行。

但是您的查询可能返回重复的行。尝试在 Query Analyzer / SQL Management Studio 中调试您的查询 - CROSS JOIN 看起来很可疑。

于 2013-07-02T07:02:03.420 回答