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();
答案 0 :(得分:0)
我的数据库不包含重复的行。
但您的查询可能正在返回重复的行。尝试在Query Analyzer / SQL Management Studio中调试查询 - CROSS JOIN看起来很可疑。