0

我试图从我的 VB.net 程序中的存储过程中获取一个字符串 (nvarchar)。当我在 SQL Studio 中运行 SP 时,它很好,但是当我尝试在程序中运行它时,我得到了错误:

Error converting data type nvarchar to int.

这是我的SP:

ALTER PROCEDURE cusVerifyAssignment
@assignment_number int,
@compass_or_anodes char(1),
@return nvarchar(1000) OUTPUT
    AS
    BEGIN
SET NOCOUNT ON;

-- Insert statements for procedure here
IF @compass_or_anodes = 'C'
BEGIN
    SET @return = 
    (SELECT CONVERT(nvarchar(1000), p.display_name + '|' + ISNULL(xro.release_type, '') + '|' + a.comments + '|' + a.assignment_id) as blah
        FROM Workplace_base.dbo.people p
        INNER JOIN Workplace_base.dbo.assignments a ON p.people_id = a.people_id
        LEFT OUTER JOIN Workplace_base.dbo.xro_assignment_release_types xro ON a.release_type_id = xro.release_type_id
    WHERE assignment_num = @assignment_number)
END
ELSE
BEGIN
    SET @return = 
    (SELECT CONVERT(nvarchar(1000), p.display_name + '|' + ISNULL(xro.release_type, '') + '|' + a.comments + '|' + a.assignment_id) as blah
        FROM Anodes_Compass.dbo.people p
        INNER JOIN Anodes_Compass.dbo.assignments a ON p.people_id = a.people_id
        LEFT OUTER JOIN Anodes_Compass.dbo.xro_assignment_release_types xro ON a.release_type_id = xro.release_type_id
    WHERE assignment_num = @assignment_number)
END
END
GO

这是我的vb代码:

    Dim paramNumber As New OleDbParameter("@assignment_number", SqlDbType.Int)
    Dim paramDB As New OleDbParameter("@compass_or_anodes", SqlDbType.Char)
    Dim paramReturn As New OleDbParameter("@return", SqlDbType.NVarChar)

    Dim reader As OleDbDataReader

    paramNumber.Value = assignmentNumber
    paramDB.Value = "C"
    paramReturn.Direction = ParameterDirection.Output


    cmd = New OleDbCommand("cusVerifyAssignment", con)
    cmd.CommandType = CommandType.StoredProcedure

    cmd.Parameters.Add(paramNumber)
    cmd.Parameters.Add(paramDB)
    cmd.Parameters.Add(paramReturn)

    con.Open()
    reader = cmd.ExecuteReader()
    con.Close()

    Return reader.GetString(0)

我也尝试过使用 executeNonQuery,但这让我得到了同样的结果。任何人都可以提供任何建议吗?

谢谢

4

1 回答 1

0

执行标量?应该允许返回单个值。

于 2012-07-17T21:15:35.553 回答