1

我正在尝试开发一个 ASP.NET 页面,该页面将显示我的数据库中的条目。我的查询中有大约 16 列。但是,如果我在代码中使用所有 16 列进行查询,则 GridView 不会显示。

只有当我的查询中的列数不超过 8 列时,它才会出现在页面上。我不知道该怎么办 有人可以帮我吗?

这些是查询的代码示例和填充查询的 bask end

 <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
        GridLines="None" Width="900px">
        <AlternatingRowStyle BackColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>

这就是我填充它的方式:

Try
        myconn.Open()
        Dim sqlstring As String = "SELECT a.account_id AS 'No', a.accountid_number AS 'ID', CONCAT(account_name,' ',account_midname,' ',account_surname ) AS 'Student Name', a.account_type As 'Type', l.live_mail AS 'Acount Name' AS 'Password' FROM account a, liveaccount l WHERE a.account_id = l.l_account_id"
        Dim smd As MySqlCommand
        smd = New MySqlCommand(sqlstring, myconn)
        smd.CommandType = CommandType.Text

        Dim da As New MySqlDataAdapter(smd)
        Dim cb As New MySqlCommandBuilder(da)
        Dim ds As New DataSet()
        da.Fill(ds)

        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()

        myconn.Close()
    Catch ex As Exception
        myconn.Close()
    End Try

这是有效的查询。如果我再添加一列,它就不会显示:

SELECT a.account_id AS 'No', a.accountid_number AS 'ID', CONCAT(account_name,' ',account_midname,' ',account_surname ) AS 'Student Name', a.account_type As 'Type', l.live_mail AS 'Acount Name' FROM account a, liveaccount l WHERE a.account_id = l.l_account_id"

这个应该可以工作,但如果我插入它,gridView 不会显示:

SELECT a.account_id AS 'No', a.accountid_number AS 'ID', a.account_type AS 'Type', a.account_name || ' ' || a.account_midname || ' ' || a.account_surname  AS 'Student Name', a.account_birthdate AS 'BirthDate', l.gender AS 'Gender', l.position AS 'Position', l.office_department AS 'Office/Department', l.date_created AS 'Date Created', time_created AS 'Time Created', l.office_tel AS 'Tel No', office_localno AS 'Office Tel', l.contact_no 'Cell Phone', l.alternate_email AS 'Other Email', l.classification AS 'Classification', l.registered AS 'Status' FROM account a, liveaccount l WHERE a.account_id = l.l_account_id AND l.registered = 'NOTREGISTERED' AND a.account_deleted = 0 ORDER BY a.account_id Desc;
4

1 回答 1

0

运行查询后,您是否验证过您的 DataSet 有任何数据?您可以尝试将您的 SQL 粘贴到管理工作室或查询分析器中,看看您的 SQL 代码是否有问题。

此外,您正在使用 try/catch,但没有捕获任何特定的异常。我会把它改成这样。这是 C#,你应该能够很容易地翻译成 VB。

catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString());}

这将显示加载数据时实际发生的情况,以及数据绑定的任何错误。

于 2013-02-25T00:19:33.393 回答