将数据类型int转换为nvarchar时出错

时间:2013-03-26 09:56:49

标签: sql database stored-procedures vb6

我收到错误 - 错误 - 将数据类型'int'转换为nvarchar

这是VB6代码:

Private Sub Form_Load()
On Error GoTo ErrDoor
Dim lvRS_Status As New ADODB.Recordset
    If gFn_OpenCnn = True Then
    If lvRS_Status.State = adStateOpen Then lvRS_Status.Close
      lvRS_Status.Open "Select Sts_StatusID,Sts_StatusDesc from Status_mst", gvCnn_CBSBSDB, adOpenDynamic, adLockOptimistic, adCmdText
      If lvRS_Status.RecordCount <> 0 Then
        Dcbo_Status.ListField = "Sts_StatusDesc"
        Dcbo_Status.BoundColumn = "Sts_StatusID"
        Set Dcbo_Status.RowSource = lvRS_Status
      End If

    End If
On Error GoTo 0
Exit Sub
ErrDoor:
    MsgBox Error$, vbExclamation
End Sub

Private Sub Cmd_OK_Click()
On Error GoTo ErrDoor
Dim lvStr_Month As String
Dim lvStr_Year As String
Dim lvStr_SelectionFormula As String
Dim lvStr_StationName As String
Dim lvDbl_CurrentSessionID As Double
lvStr_SelectionFormula = ""
 lvDbl_CurrentSessionID = Int((2000 * Rnd) + 1000)

    gvCnn_CBSBSDB.BeginTrans
    gvCnn_CBSBSDB.Execute "Exec DBPrc_SundryDebrorAgewiseDetails " & lvDbl_CurrentSessionID & ", '" & Dcbo_Status.BoundText & "', " & Cbo_SelectMonth.ListIndex + 1 & ", " & Txt_SelectYear.Text & ""
    gvCnn_CBSBSDB.CommitTrans


    Crpt_SundryDebtor.Reset
    Crpt_SundryDebtor.WindowState = crptMaximized


    Crpt_SundryDebtor.ReportFileName = App.Path & "\sundrydebtor_agewise.rpt"
    Crpt_SundryDebtor.DiscardSavedData = True
   If Trim(Cbo_SelectMonth.Text) <> "" Then
       lvStr_Month = "{SundryDebtors_AgeWise.lvStr_Month} = " & Cbo_SelectMonth.ItemData(Cbo_SelectMonth.ListIndex)
       lvStr_SelectionFormula = lvStr_Month
   Else
       MsgBox "Select the month ", vbInformation, "Sundry Debtor Age wise"
       Exit Sub
   End If


   If Trim(Txt_SelectYear.Text) <> "" Then

           lvStr_Month = lvStr_SelectionFormula + " And {SundryDebtors_AgeWise.Sde_Year}  =" & Txt_SelectYear.Text
           lvStr_SelectionFormula = lvStr_Month

    End If


    If Trim(Dcbo_Status.Text) <> "" Then
        If lvStr_SelectionFormula <> "" Then
           lvStr_Month = lvStr_SelectionFormula + " And {Status_Mst.Sts_StatusID} =" & val(Dcbo_Status.BoundText) & ""
           lvStr_SelectionFormula = lvStr_Month
        End If
    End If


    Crpt_SundryDebtor.SelectionFormula = "{Reporter.Session_ID} = " & lvDbl_CurrentSessionID & ""
        Crpt_SundryDebtor.Connect = gvCnn_CBSBSDB
        Crpt_SundryDebtor.DiscardSavedData = True
        Crpt_SundryDebtor.WindowShowRefreshBtn = True
        Crpt_SundryDebtor.WindowShowPrintSetupBtn = True
        Crpt_SundryDebtor.Destination = crptToWindow
        Crpt_SundryDebtor.Action = 1



On Error GoTo 0
Exit Sub
Resume
ErrDoor:
    MsgBox Error$, vbExclamation

End Sub

这是存储过程:

CREATE PROCEDURE DBPrc_SundryDebrorAgewiseDetails(
  @SessionId as int,
  @StatusId as int,
  @Month as nvarchar,
  @Year as nvarchar)
as 
begin
if @StatusId=''
begin
    SELECT
      @SessionId,
      Sts_StatusDesc, Agt_AgentName,Sde_OutstandingAsOnDate,
      Sde_AmountLessThanSixMonths,
      Sde_AmountBetweenSixMonthstoOneYear,Sde_AmountBetweenOneToTwoYear,
      Sde_AmountBetweenTwoToThreeYears,Sde_AmountMoreThanThreeYears,
      Sde_TotalAdChanrges,Sde_TotalProgressiveInterest,Sde_TotalOutstandingAsOnDate,
      Sde_Remark, Sde_SundryDebtorCode
    FROM SundryDebtors_AgeWise left join Status_Mst
           on sts_StatusId=Sde_StatusId
         left join Agent_Mst
           on Agt_AgentId=Sde_AgentId
    WHERE SundryDebtors_AgeWise.Sde_Month=@Month 
      and SundryDebtors_AgeWise.Sde_Year=@Year 
    GROUP BY Sts_StatusDesc, Agt_AgentName,Sde_OutstandingAsOnDate,Sde_AmountLessThanSixMonths,Sde_AmountBetweenSixMonthstoOneYear,Sde_AmountBetweenOneToTwoYear,Sde_AmountBetweenTwoToThreeYears,Sde_AmountMoreThanThreeYears,Sde_TotalAdChanrges,Sde_TotalProgressiveInterest,Sde_TotalOutstandingAsOnDate,Sde_Remark,Sde_SundryDebtorCode

End

If @StatusId<>''
Begin

    SELECT
      @SessionId,
      Sts_StatusDesc,Agt_AgentName,Sde_OutstandingAsOnDate,
      Sde_AmountLessThanSixMonths,Sde_AmountBetweenSixMonthstoOneYear,
      Sde_AmountBetweenOneToTwoYear,Sde_AmountBetweenTwoToThreeYears,
      Sde_AmountMoreThanThreeYears,Sde_TotalAdChanrges,Sde_TotalProgressiveInterest,
      Sde_TotalOutstandingAsOnDate,Sde_Remark,Sde_SundryDebtorCode
    FROM SundryDebtors_AgeWise left join Status_Mst
           on sts_StatusId=Sde_StatusId
         left join Agent_Mst
         on Agt_AgentId=Sde_AgentId
    WHERE SundryDebtors_AgeWise.Sde_Month=@Month 
      and SundryDebtors_AgeWise.Sde_Year=@Year 
      and Sts_StatusId=@StatusId
    GROUP BY Sts_StatusDesc, Agt_AgentName,Sde_OutstandingAsOnDate,Sde_AmountLessThanSixMonths,Sde_AmountBetweenSixMonthstoOneYear,Sde_AmountBetweenOneToTwoYear,Sde_AmountBetweenTwoToThreeYears,Sde_AmountMoreThanThreeYears,Sde_TotalAdChanrges,Sde_TotalProgressiveInterest,Sde_TotalOutstandingAsOnDate,Sde_Remark,Sde_SundryDebtorCode
End

End
GO

1 个答案:

答案 0 :(得分:1)

您的SP参数是int:
@StatusId as int,

...但你正在测试空字符串'':
if @StatusId=''