对象或列名称为空

时间:2015-01-19 22:37:50

标签: asp.net sql-server vb.net

我有以下DataGrid:

<asp:DataGrid id="Visits_DataGrid" runat="server" BorderColor="#333333" BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" AutoGenerateColumns="False" BackColor="White" CellPadding="0" Width="100%" AllowSorting="True" OnItemCommand="VisitsDataGrid_Click" OnSortCommand="Visits_DataGrid_SortCommand" OnSelectedIndexChanged="DataGrid_SelectedIndexChanged">
<ItemStyle ForeColor="#4A3C8C" />
<AlternatingItemStyle BackColor="#EEEEEE" />
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#333333" />
<Columns>
    <asp:BoundColumn HeaderText="" DataField="VisitID" Visible="false"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Deadline Date" SortExpression="ORDER BY DeadlineDate">
        <ItemTemplate>
            <%# String.Format("{0:d}", DataBinder.Eval(Container.DataItem, "DeadlineDate")) %>
        </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn HeaderText="Assigned Staff Member" DataField="StaffName" SortExpression="ORDER BY StaffName"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="" DataField="StatusID" Visible="false"></asp:BoundColumn>
    <asp:BoundColumn HeaderText="Status" DataField="Status" SortExpression="ORDER BY StatusID"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Scheduled Date" SortExpression="ORDER BY ScheduledDate">
        <ItemTemplate>
            <%# String.Format("{0:d}", DataBinder.Eval(Container.DataItem, "ScheduledDate")) %>
        </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn HeaderText="Created By" DataField="createdName" SortExpression="ORDER BY createdName"></asp:BoundColumn>
    <asp:ButtonColumn Text="" HeaderText="" CommandName="Select" Visible="true"></asp:ButtonColumn>
    </Columns>
    <PagerStyle HorizontalAlign="Right" CssClass="pagingStyle" Mode="NumericPages" BackColor="#D3DEEF" />
</asp:DataGrid>

以下子w / select查询,即插入此数据网格:

Sub Visit_Load()
    Dim strSQL As String
    Dim DAL As DAL.DataAccess = New DAL.DataAccess
    Dim ds As New DataSet

    strSQL = "SELECT TAV.VisitID, TAV.DeadlineDate, TU1.first_name + ' ' + TU1.last_name as StaffName, TAV.StatusID, TAVS.Status, TAV.ScheduledDate, TU2.first_name + ' ' + TU2.last_name as createdName " & _
        " from tblAgentVisit as TAV " & _
        " left join tblUser as TU1 on TAV.assignedStaff = TU1.user_id " & _
        " left join tblUser as TU2 on TAV.Created_user_id = TU2.user_id " & _
        " left join tblAgentVisitAgents as TAVA on TAV.VisitID = TAVA.VisitID " & _
        " left join tblAgentVisitStatus_L as TAVS on TAV.StatusID = TAVS.StatusID " & _
        " WHERE TAVA.AgtID = " & Utils.NumOrNull(agentID_Label.text) & _
        " AND TAVA.Prime = 1"
    strSQL &= " " & OrderGrid_Label.text    

    strSQL = Utils.replaceChars(strSQL)
    ds = DAL.ExecDataSet(strSQL, CommandType.Text)

    Visits_DataGrid.DataSource = ds
    Visits_DataGrid.DataBind()
End Sub

我继续收到以下错误:An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.我一遍又一遍地检查,无法找到我失踪的地方。其他人可以看到吗?

1 个答案:

答案 0 :(得分:0)

我发现了这个问题,但尚未解决问题。

当我尝试使用TU1.first_name + ' ' + TU1.last_name as StaffName选择人名时,它不喜欢添加的空格并引发错误。

我可以TU1.first_name + TU1.last_name as StaffName,但它工作正常,但名称格式化全部关闭。关于如何解决这个问题的建议?