在所选数据源x上找不到具有名称的字段或属性

时间:2014-03-24 18:31:25

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

我以前遇到过这个,但我不记得我是如何处理它的。

使用ASP / VB.NET 4.0构建网站,访问MSSQL v.2005数据库,填充gridview。此网页正常工作,直到我在网址中添加代码来处理参数:.../ETL_S_EXPORT_MM002.aspx?VEN=74&ALL=y

该页面仅显示之前视图中的*,但现在它坚持Vendor_Name_1不存在。如果我评论所有对此的引用,它会坚持Vendor_Name_2不存在。我在我的智慧结束,有人请救救我......

SQL数据源:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ERPConnectionString %>" 
    SelectCommand="SELECT Vendor_Number
                        , Vendor_Name_1
                        , Vendor_Name_2
                        , ETLID
                        , remits_Seq 
                     FROM [dbo].[...]" >
</asp:SqlDataSource>

的GridView:

<asp:GridView ID="GridView1" 
    runat="server" 
    AllowPaging="True" 
    PageSize="200"
    AllowSorting="True" 
    AutoGenerateColumns="False" 
    GridLines="Vertical"
    DataSourceID="SqlDataSource1" 
    CellPadding="4"
    CssClass="gridviewPageGRID">
    <AlternatingRowStyle CssClass="gridviewAlternatingRowStyleGRID"/>
    <Columns>
        <asp:TemplateField HeaderText="Vendor Number"  SortExpression="Vendor_Number">
            <ItemTemplate>
                <div style="width:120px; text-align:center;">
                    <asp:Label ID="l2" runat="server" Text='<%# Eval("Vendor_Number")%>'/>
                </div>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:HyperLinkField 
            DataTextField="remits_Seq"
            HeaderText="Remit Sequence"
            SortExpression="remits_Seq"
            ItemStyle-HorizontalAlign="Center"
            DataNavigateUrlFields="remits_Seq, Vendor_Number" 
            DataNavigateUrlFormatString ="ETL_S_EXPORT_MM002_ONE.aspx?RS={0}&VN={1}">
            <ItemStyle HorizontalAlign="Center"></ItemStyle>
        </asp:HyperLinkField>
        <asp:BoundField DataField="Vendor_Name_1"   HeaderText="Vendor Name 1" SortExpression="Vendor_Name_1" />
        <asp:BoundField DataField="Vendor_Name_2"   HeaderText="Vendor Name 2" SortExpression="Vendor_Name_2" />
    </Columns>
</asp:GridView>

代码后面添加“where”语句进行查询,如果需要(db是一个负责构建where语句的对象):

Dim flag As String = Request.QueryString("ALL")
Dim db As New classDashBoard
db.ObjectKey = "MM002"
db.parmVNA = Request.QueryString("VNA")
db.parmVEN = Request.QueryString("VEN")
db.selectFilterParm()
If flag = "n" Then
    If db.Filter = "" Then
        If db.parmVNA <> "" Then db.Filter = "Vendor_Name_1 LIKE '%" & db.parmVNA & "%'"
    Else
        If db.parmVNA <> "" Then db.Filter &= " OR Vendor_Name_1 LIKE '%" & db.parmVNA & "%'"
    End If
    If db.Filter = "" Then
        If db.parmVEN <> "" Then db.Filter = "Vendor_Number LIKE '%" & db.parmVEN & "%'"
    Else
        If db.parmVEN <> "" Then db.Filter &= " OR Vendor_Number LIKE '%" & db.parmVEN & "%'"
    End If
ElseIf flag = "y" Then
    If db.Filter = "" Then
        If db.parmVNA <> "" Then db.Filter = "Vendor_Name_1 LIKE '%" & db.parmVNA & "%'"
    Else
        If db.parmVNA <> "" Then db.Filter &= " AND Vendor_Name_1 LIKE '%" & db.parmVNA & "%'"
    End If
    If db.Filter = "" Then
        If db.parmVEN <> "" Then db.Filter = "Vendor_Number LIKE '%" & db.parmVEN & "%'"
    Else
        If db.parmVEN <> "" Then db.Filter &= " AND Vendor_Number LIKE '%" & db.parmVEN & "%'"
    End If
  End If
db.countAllRecords()
db.countSomeRecords()
db.buildCountsHeader()
db.buildCountsSQL()
'   ----------------------
'   Add header to the page
'   ----------------------
Panel1.Controls.Add(New LiteralControl(db.counts_header))
'   -------------------------------------
'   Adjust the SQL according to the Parms
'   -------------------------------------
Me.SqlDataSource1.SelectCommand = db.counts_SQL

观点:

SELECT COALESCE (m.Vendor_Number, '') AS Vendor_Number
     , COALESCE (m.Vendor_Name_1, '') AS Vendor_Name_1
     , COALESCE (m.Vendor_Name_2, '') AS Vendor_Name_2
     , COALESCE (m.remits_Seq   , '') AS remits_Seq
     , COALESCE (m.ETLID        , '') AS ETLID
  FROM....

如您所见,视图中存在所有行。

谢谢大家的时间。让我知道我可以回答的任何问题。

3-31-2014任何人都可以帮忙吗?

0 个答案:

没有答案