SQL Server存储过程不会将数据返回到类,但在SQL Server Management Studio中可以正常工作

时间:2015-04-21 17:33:09

标签: sql-server vb.net visual-studio-2012

我正在尝试从vb类和类中检索此SQL Server存储过程中的数据:

Dim GetDailySalesAmateurRptOrderItems_DataArray(,) As String = 
oDAL.GetDailySalesAmateurRptOrderItems("2014-04-17", "2014-04-20")

即使数据库中有足够的数据,它也不会向数组返回任何内容......任何想法是什么导致了这个问题?

USE [QUICKFIX_COLOR_LAB_POS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[GetDailySalesAmateurRptOrderItems] 
   @FromDate Datetime, @ToDate Datetime
as
   SELECT        
       ITEMS.ItemID, ITEMS.ItemName, ORDER_ITEMSET.Qty, 
       ORDER_ITEMSET.SoldPrice, ORDERS.OrderTimestamp
   FROM            
       ORDERS 
   INNER JOIN
       ORDER_ITEMSET ON ORDERS.OrderID = ORDER_ITEMSET.OrderID 
   INNER JOIN
       CUSTOMER_ACCOUNTS ON ORDERS.CustomerID = CUSTOMER_ACCOUNTS.CUSTOMER_ID 
   CROSS JOIN
       ITEMS
   WHERE        
       (CUSTOMER_ACCOUNTS.CUSTOMER_CATEGORY = 'Amateur') 
       AND (ORDERS.OrderTimestamp BETWEEN CONVERT(DATETIME, @FromDate, 102) AND CONVERT(DATETIME, @ToDate, 102))
   ORDER BY 
       ITEMS.ItemID

VB功能

    Function GetDailySalesAmateurRptOrderItems(DateFrom As String, ByVal DateTo As String)
        Try
            Dim DateFrom_Date As DateTime = DateFrom
            Dim DateTo_Date As DateTime = DateTo
            Dim output(,) As String
            Dim counter As Integer
            Dim cmd As New SqlCommand("GetDailySalesAmateurRptOrderItems", DBconn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@FromDate", DateFrom_Date)
            cmd.Parameters.AddWithValue("@ToDate", DateTo_Date)
            Dim reader As SqlDataReader
            DBconn.Open()
            reader = cmd.ExecuteReader
            While reader.Read()
                counter = counter + 1
            End While
            ReDim output(counter - 1, 0 To 4)
            counter = 0
            reader.Close()
            reader = cmd.ExecuteReader
            While reader.Read()
                output(counter, 0) = reader(0)
                output(counter, 1) = reader(1)
                output(counter, 2) = reader(2)
                output(counter, 3) = reader(3)
                output(counter, 4) = reader(4)
                counter = counter + 1
            End While
            DBconn.Close()
            Return output
        Catch ex As Exception
            Return ex.Message
        End Try
    End Function

0 个答案:

没有答案