SQL过程通过标准查询而不是应用程序查询返回行

时间:2014-10-30 14:12:01

标签: sql-server vb.net

现在这很奇怪,我有这个程序:

@ProjectId INT,
@ChecksheetId INT,
@QualId INT,
@includeDeleted BIT = 0

AS

BEGIN

SELECT  CheckSheetQual.CheckSheetQualId, CheckSheetQual.CheckSheetQualSheetId, CheckSheetQual.CheckSheetQualQualId, CheckSheetQual.CheckSheetQualProjectId, CheckSheetQual.CheckSheetQualAddedById, CheckSheetQual.CheckSheetQualAddedAt,
        CheckSheetQual.CheckSheetQualDeleted, CheckSheetQual.CheckSheetQualDeletedById, CheckSheetQual.CheckSheetQualDeletedAt,
        Quals.QualsTitle, Quals.QualsDesc, Quals.QualsDuration, DeletedUser.UserFullName AS CheckSheetQualDeletedBy,
        CheckSheetQual.CheckSheetQualAddedBy, Project.ProjectDesc, Checksheet.CheckSheetName, CheckSheetDescription, CheckSheetRevision, 
        Discipline.DisciplineRef, L_CheckTypeDesc
FROM    dbo.[ChecksheetQual] INNER JOIN
        dbo.Quals ON ChecksheetQual.CheckSheetQualQualId = Quals.QualsID INNER JOIN
        dbo.Checksheet ON Checksheet.ChecksheetId = ChecksheetQual.ChecksheetQualSheetId INNER JOIN
        dbo.Discipline ON Checksheet.ChecksheetDiscipline = Discipline.DisciplineId INNER JOIN
        dbo.L_CheckType ON Checksheet.CheckSheetType = L_CheckType.L_CheckTypeId INNER JOIN
        dbo.Project ON ChecksheetQual.ChecksheetQualProjectId = Project.ProjectId LEFT JOIN
        dbo.[User] AS DeletedUser ON ChecksheetQual.CheckSheetQualDeletedById = DeletedUser.UserId
WHERE   
        dbo.Project.ProjectId = @ProjectId
AND
        (dbo.CheckSheetQual.CheckSheetQualSheetId = @ChecksheetId)
AND

        (dbo.CheckSheetQual.CheckSheetQualDeleted = @includeDeleted)

select语句是一个巨大的,我知道,但它可以被忽略,因为我知道它有效,我会告诉你为什么......

现在让我说我想把includeDeleted设置为1的项目(已删除的项目),所以,在sql管理器中运行此查询:

EXEC dbo.prc_ChecksheetQual_Get_List @ProjectId = 1, @ChecksheetId = 378, @QualId = 0,  @includeDeleted = 1;
GO

结果如预期的那样返回正确的行,其中3行实际上是。

现在假设我想在应用程序中执行相同的操作:

 Dim sqlConn As New SqlConnection(Me.Variables.ConnectionString)
        Dim sqlComm As New SqlCommand
        Dim sqlDR As SqlDataReader = Nothing

        Try
            With sqlComm
                .CommandText = "prc_ChecksheetQual_Get_List"
                .CommandType = CommandType.StoredProcedure
                .CommandTimeout = Me.Variables.CommandTimeout
                .Connection = sqlConn
                .Parameters.Clear()
                .Parameters.Add("@ProjectId", SqlDbType.Int).Value = 1
                .Parameters.Add("@ChecksheetId", SqlDbType.Int).Value = 378
                .Parameters.Add("@QualId", SqlDbType.Int).Value = 0
                .Parameters.Add("@includeDeleted", SqlDbType.Bit).Value = 1
            End With

            If sqlConn.State <> ConnectionState.Closed Then sqlConn.Close()
            sqlConn.Open()
            sqlDR = sqlComm.ExecuteReader(CommandBehavior.CloseConnection)

            If sqlDR.HasRows Then
                list = New List(Of ChecksheetQualCLS)
                While sqlDR.Read
                    list.Add(FillDataRecord(sqlDR))
                End While
            End If

SAME确切的值被传递,但是它返回0行,所以没关系,有些错误,但是,让我们尝试相同但获取未删除的项目......

.Parameters.Add("@includeDeleted", SqlDbType.Bit).Value = 0

返回正确的金额和正确的行数。这怎么可能?

我在这里完全失败,请帮助。

0 个答案:

没有答案