')'附近的语法不正确。关键字“on”附近的语法不正确

时间:2011-06-15 19:32:57

标签: vb.net

我是VB.NET的新手。我正在尝试将表添加到ASPX页面。但是我使用以下代码得到了上述错误。你能说出我做错了什么吗?我想要返回很多表行;每个产品一个,其中第一个单元格=产品名称,单元格2 = NumOpen,单元格3 = 95%。

<HTML>
<SCRIPT LANGUAGE="VB" RUNAT="Server">
    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)

        If Not IsPostBack Then              
            Dim YearDate As Date = "1/1/05"
            Dim arrYear As New ArrayList()

            While YearDate <= Today
                arrYear.Add(YearDate.ToString("yyyy"))
                YearDate = YearDate.AddYears(1)
            End While

            dYear.DataSource = arrYear
            dYear.DataBind()
            dYear.SelectedValue = Today.AddMonths(-1).ToString("yyyy")

            Dim ListMonth As Date = "1/1/08"
            Dim arrListMonth As New ArrayList()
            While ListMonth <= "12/1/08"
                arrListMonth.Add(ListMonth.ToString("MMM"))
                ListMonth = ListMonth.AddMonths(1)
            End While

            dEndMonth.DataSource = arrListMonth
            dEndMonth.DataBind()
            dEndMonth.SelectedValue = Today.AddMonths(-1).ToString("MMM")

        Else

        End If
        Main()

    End Sub

    Sub Main()

        Dim FirstMonthDate As Date = CDate(dYear.SelectedValue & "-" & dEndMonth.SelectedValue & "-1")
        FirstMonthDate = FirstMonthDate.AddMonths(-2)
        Dim LastMonthDate As Date = GlobalFunctions.GlobalF.MonthLastDate(dYear.SelectedValue & "-" & dEndMonth.SelectedValue & "-1")

        Dim arrMonths As New ArrayList()

        While FirstMonthDate <= LastMonthDate
            arrMonths.Add(GlobalFunctions.GlobalF.MonthLastDate(FirstMonthDate).ToString)
            FirstMonthDate = FirstMonthDate.AddMonths(1)
        End While

        Dim monthString As String

        Dim ProductList As String = "SELECT DISTINCT  PRODUCT FROM EXCEL.DMR_PRODUCT"
        Dim ProductListData As New System.Data.DataSet
        ProductListData = GlobalFunctions.GlobalF.GetDevSQLServerDataSet(ProductList)

        Dim ProductRow As DataRow
        Dim y As Integer = 0
        Dim arrayProducts() As String

        Dim ProductTableRow As New HtmlTableRow
        Dim ProductTableCell As New HtmlTableCell
        ProductTableCell.InnerText = "Products"
        ProductTableRow.Cells.Add(ProductTableCell)
        ProductTableCell.Attributes.Add("class", "HeaderRow")

        Dim NumOpenCell As New HtmlTableCell
        NumOpenCell.InnerText = "Number Open"
        ProductTableRow.Cells.Add(NumOpenCell)
        NumOpenCell.Attributes.Add("class", "HeaderRow")
        NumOpenCell.Width = 100

        Dim ComplaintCell As New HtmlTableCell
        ComplaintCell.InnerText = "% Of Open Complaints Complaints < 90 Days - Rolling 3 Month"
        ProductTableRow.Cells.Add(ComplaintCell)
        ComplaintCell.Attributes.Add("class", "HeaderRow")
        ComplaintCell.Width = 100

        Dim NumOpenList As String

        table1.Rows.Add(ProductTableRow)

        For Each ProductRow In ProductListData.Tables(0).Rows

            For Each monthString In arrMonths

            Next

            ReDim Preserve arrayProducts(y)
            arrayProducts(y) = ProductRow("PRODUCT")

            ProductTableRow = New HtmlTableRow
            ProductTableCell = New HtmlTableCell
            ProductTableCell.InnerText = arrayProducts(y)
            ProductTableRow.Cells.Add(ProductTableCell)

            NumOpenList = "SELECT COUNT([FORMAT NUMBER]) " & _
  "FROM(ALL_COMPLAINTS) " & _
  " join (SELECT * FROM dbo.ProductPartNumbers(' " & _
  arrayProducts(y) & _
  " ')) on EPA_PRD_CODE like '%' + [FORMAT NUMBER] + '%' "
            Dim NumOpenListData As New System.Data.DataSet
            NumOpenListData = GlobalFunctions.GlobalF.GetDevSQLServerDataSet(NumOpenList)

            NumOpenCell = New HtmlTableCell
            NumOpenCell.InnerText = NumOpenList
            ProductTableRow.Cells.Add(NumOpenCell)

            ComplaintCell = New HtmlTableCell
            ComplaintCell.InnerText = "95%"
            ProductTableRow.Cells.Add(ComplaintCell)

            table1.Rows.Add(ProductTableRow)
            y = y + 1
        Next
    End Sub

2 个答案:

答案 0 :(得分:0)

打印出numOpenList。这就是你设置的方式。

        NumOpenList = "SELECT COUNT([FORMAT NUMBER]) " & _ 
  "FROM(ALL_COMPLAINTS) " & _ 
  " join (SELECT * FROM dbo.ProductPartNumbers(' " & _ 
  arrayProducts(y) & _ 
  " ')) on EPA_PRD_CODE like '%' + [FORMAT NUMBER] + '%' " 

现在,设置断点并获取实际字符串。然后检查以确保你有相同数量的(和)。我打赌你会发现更多的其中一个。修复它,你的代码是固定的。

如果我是对的,你可能会在这里爆炸:

NumOpenListData = GlobalFunctions.GlobalF.GetDevSQLServerDataSet(NumOpenList) 

或者在GlobalFunctions库中的实际GetDevSqlServerDataSet函数中。

答案 1 :(得分:0)

问题在于:

NumOpenList = "SELECT COUNT([FORMAT NUMBER]) " & _
 "FROM(ALL_COMPLAINTS) " & _
 " join (SELECT * FROM dbo.ProductPartNumbers(' " & _
 arrayProducts(y) & _
 " ')) on EPA_PRD_CODE like '%' + [FORMAT NUMBER] + '%' "

问题是你的SQL无效。如果(SELECT ...)之后没有别名,则无法直接加入SELECT。 (我还应该提到这是编写得非常糟糕的代码,你应该打破使用非参数化查询的习惯。)

你的SQL正在沸腾:

SELECT COUNT([FORMAT NUMBER]) FROM (ALL_COMPLAINTS) 
  join (SELECT * FROM dbo.ProductPartNumbers('somepartnumber'))
 on EPA_PRD_CODE like '%something%' 

如果您尝试填充手动连接并运行SQL的部件,则无法正常工作。