数据转换日期错误到int但似乎所有匹配

时间:2015-01-29 10:22:46

标签: sql vb.net adodb

不允许从数据类型datetime到tinyint的隐式转换。使用CONVERT函数运行此查询。是错误我和Varchar相处的日期,我知道这个问题的正常问题,但我似乎无法解决这个问题。

我有以下代码调用SP的代码:

  Public Function SavePropertyExpiries() As Boolean
    '** Save Current Personal Data Record

    ' Error Checking
    'On Error GoTo Err_SaveProperty

    ' Dimension Local Variables
    Dim uRecSnap As ADODB.Recordset



    ' Check For Open Connection
    If uDBase Is Nothing Then
        OpenConnection()
        bConnection = True
    End If

    ' Run Stored Procedure - Save PropertyExpiries Record
    uCommand = New ADODB.Command
    With uCommand
        .ActiveConnection = uDBase
        .CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
        .CommandTimeout = 0

        uCommand.Parameters.Append(uCommand.CreateParameter("@PropertyID", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInput, , Val(lblPropertyIDValue.Text)))
        uCommand.Parameters.Append(uCommand.CreateParameter("@HMOLicenced", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkHMOLicenced.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@HMOExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpHMOExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@HMOLicenseRef", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 60, txtHMOLicenseRef.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@HMONotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtHMONotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@GasSafetyCheck", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkGasSafetyCheck.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@GasSafetyExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpGasSafetyExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@GasSafetyNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtGasSafetyNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PAT", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkPAT.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PATExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpPATExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PATNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtPATNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EICR", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkEICR.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EICRExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpEIRCExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EICRNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtEIRCNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@FireSafety", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkFireSafety.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@FiresafetyExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpFiresafetyExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@FireSafetyNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtFiresafetyNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EPC", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkEPC.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EPCExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpEPCExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EPCRating", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , cmbEPCRating.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@EPCNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtEPCNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@Insurance", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkInsurance.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@InsurenceExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpInsurenceExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@InsurenceNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtInsurenceNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PropertyInspection", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkPropertyInspection.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PropertyInspectionDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpPropertyInspectionDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PropertyInspectionInMonths", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , nudPropertyInspectionInMonths.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@PropertyInspectionNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtPropertyInspectionNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@LandLordRegistration", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkLandLordRegistration.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@LandLordRegistrationExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpLandLordRegistrationExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@LandlordRegistrationNo", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtLandlordRegistrationNo.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@LandlordRegistrationNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtLandlordRegistrationNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@NextRentReview", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkNextRentReview.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@NextRentReviewExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpNextRentReviewExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@NextRentreviewNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtNextRentreviewNotes.Text))
        uCommand.Parameters.Append(uCommand.CreateParameter("@ManagementFeeReview", ADODB.DataTypeEnum.adTinyInt, ADODB.ParameterDirectionEnum.adParamInput, , -chkManagementFeeReview.Checked))
        uCommand.Parameters.Append(uCommand.CreateParameter("@ManagementExpiryDate", ADODB.DataTypeEnum.adDate, ADODB.ParameterDirectionEnum.adParamInput, , dtpManagementExpiryDate.Value))
        uCommand.Parameters.Append(uCommand.CreateParameter("@ManagementfeeReviewNotes", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 100, txtManagementfeeReviewNotes.Text))

        .CommandText = "PropertyExpiries_SaveRecord"

        .Execute()
    End With

    ' Close Connection
    uRecSnap = Nothing
    uCommand = Nothing
    If bConnection Then CloseConnection()
    SavePropertyExpiries = True

Err_SaveProperty:
    If Err.Number <> 0 Then
        sErrDescription = Err.Description
        WriteAuditLogRecord("clsPropertyExpiries", "SaveExpiries", "Error", sErrDescription)
        SavePropertyExpiries = False
    End If

 End Function

Herer是SP itselft:

    ALTER PROCEDURE [dbo].[PropertyExpiries_SaveRecord] 
    -- Add the parameters for the stored procedure here
     @PropertyID as int, @HMOLicenced as tinyint, @HMOExpiryDate as date, @HMOLicenseRef as varchar(60), @HMONotes as varchar(60), 
    @GasSafetyCheck as tinyint, @GasSafetyExpiryDate as date, @GasSafetyNotes as varchar(100), @PAT as tinyint, 
    @PATExpiryDate as date, @PATNotes as varchar(60), @EICR as tinyint, @EICRExpiryDate as date, @EICRNotes as varchar(60), 
    @FireSafety as tinyint, @FiresafetyExpiryDate as date, @FireSafetyNotes as varchar(60), @EPC as tinyint, 
    @EPCExpiryDate as date, @EPCRating tinyint, @EPCNotes as varchar(60), @Insurance as tinyint, @InsurenceExpiryDate as date, @InsurenceNotes as varchar(60),
    @LandlordRegistrationNo as varchar(60),@PropertyInspection as tinyint, @PropertyInspectionDate as date,
    @PropertyInspectionInMonths as tinyint, @PropertyInspectionNotes as varchar(60), @LandLordRegistration as tinyint,
    @LandLordRegistrationExpiryDate as date, @LandlordRegistrationNotes as varchar(60), @NextRentReview as tinyint, @NextRentReviewExpiryDate as date, 
    @NextRentreviewNotes as varchar(60), @ManagementFeeReview as tinyint, @ManagementExpiryDate as date, @ManagementfeeReviewNotes as varchar(60)

AS

If  (SELECT ISNULL(PropertyID , 0 ) FROM  PropertyExpiries WHERE PropertyID = @PropertyID) = 0


BEGIN
        INSERT INTO PropertyExpiries (PropertyID, HMOLicenced, HMOExpiryDate, HMOLicenseRef, HMONotes, GasSafetyCheck, GasSafetyExpiryDate, GasSafetyNotes, PAT, PATExpiryDate, PATNotes, EICR, EICRExpiryDate, EICRNotes, FireSafety, FiresafetyExpiryDate, FireSafetyNotes, EPC, EPCExpiryDate, EPCRating, EPCNotes, Insurance, InsurenceExpiryDate, InsurenceNotes, PropertyInspection, PropertyInspectionDate, PropertyInspectionInMonths, PropertyInspectionNotes, LandLordRegistration, LandLordRegistrationExpiryDate, LandlordRegistrationNo, LandlordRegistrationNotes, NextRentReview, NextRentReviewExpiryDate, NextRentreviewNotes, ManagementFeeReview, ManagementExpiryDate, ManagementfeeReviewNotes)
        VALUES ( @PropertyID, @HMOLicenced, @HMOExpiryDate, @HMOLicenseRef, @HMONotes, @GasSafetyCheck, @GasSafetyExpiryDate, @GasSafetyNotes, @PAT, @PATExpiryDate, @PATNotes, @EICR, @EICRExpiryDate, @EICRNotes, @FireSafety, @FiresafetyExpiryDate, @FireSafetyNotes,  @EPC, @EPCExpiryDate, @EPCRating, @EPCNotes, @Insurance, @InsurenceExpiryDate, @InsurenceNotes, @PropertyInspection, @PropertyInspectionDate,  @PropertyInspectionInMonths, @PropertyInspectionNotes, @LandLordRegistration, @LandLordRegistrationExpiryDate, @LandlordRegistrationNo, @LandlordRegistrationNotes, @NextRentReview, @NextRentReviewExpiryDate, @NextRentreviewNotes, @ManagementFeeReview, @ManagementExpiryDate, @ManagementfeeReviewNotes)
    END

BEGIN
    UPDATE PropertyExpiries SET 

    PropertyID = @PropertyID,
    HMOLicenced = @HMOLicenced,
    HMOExpiryDate = @HMOExpiryDate,
    HMOLicenseRef = @HMOLicenseRef,
    HMONotes = @HMONotes,
    GasSafetyCheck = @GasSafetyCheck,
    GasSafetyExpiryDate = @GasSafetyExpiryDate,
    GasSafetyNotes = @GasSafetyNotes,
    PAT = @PAT,
    PATExpiryDate = @PATExpiryDate,
    PATNotes = @PATNotes,
    EICR = @EICR,
    EICRExpiryDate = @EICRExpiryDate,
    EICRNotes = @EICRNotes,
    FireSafety = @FireSafety,
    FiresafetyExpiryDate = @FiresafetyExpiryDate,
    FireSafetyNotes = @FireSafetyNotes,
    EPC = @EPC,
    EPCExpiryDate = @EPCExpiryDate,
    EPCRating = @EPCRating,
    EPCNotes = @EPCNotes,
    Insurance = @Insurance,
    InsurenceExpiryDate = @InsurenceExpiryDate,
    InsurenceNotes = @InsurenceNotes,
    PropertyInspection = @PropertyInspection,
    PropertyInspectionDate = @PropertyInspectionDate,
    PropertyInspectionInMonths = @PropertyInspectionInMonths,
    PropertyInspectionNotes = @PropertyInspectionNotes,
    LandLordRegistration = @LandLordRegistration,
    LandLordRegistrationExpiryDate = @LandLordRegistrationExpiryDate,
    LandlordRegistrationNo = @LandlordRegistrationNo,
    LandlordRegistrationNotes = @LandlordRegistrationNotes,
    NextRentReview = @NextRentReview,
    NextRentReviewExpiryDate = @NextRentReviewExpiryDate,
    NextRentreviewNotes = @NextRentreviewNotes,
    ManagementFeeReview = @ManagementFeeReview,
    ManagementExpiryDate = @ManagementExpiryDate,
    ManagementfeeReviewNotes = @ManagementfeeReviewNotes



        WHERE PropertyID = @PropertyID 
END

表:

    USE [BMSSouthSide]
GO

/****** Object:  Table [dbo].[PropertyExpiries]    Script Date: 29/01/2015 11:04:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[PropertyExpiries](
    [PropertyID] [int] NULL,
    [HMOLicenced] [tinyint] NULL,
    [HMOExpiryDate] [date] NULL,
    [HMOLicenseRef] [varchar](100) NULL,
    [HMONotes] [varchar](100) NULL,
    [GasSafetyCheck] [tinyint] NULL,
    [GasSafetyExpiryDate] [date] NULL,
    [GasSafetyNotes] [varchar](100) NULL,
    [PAT] [tinyint] NULL,
    [PATExpiryDate] [date] NULL,
    [PATNotes] [varchar](100) NULL,
    [EICR] [tinyint] NULL,
    [EICRExpiryDate] [date] NULL,
    [EICRNotes] [varchar](100) NULL,
    [FireSafety] [tinyint] NULL,
    [FiresafetyExpiryDate] [date] NULL,
    [FireSafetyNotes] [varchar](100) NULL,
    [EPC] [tinyint] NULL,
    [EPCExpiryDate] [date] NULL,
    [EPCRating] [tinyint] NULL,
    [EPCNotes] [varchar](100) NULL,
    [Insurance] [tinyint] NULL,
    [InsurenceExpiryDate] [date] NULL,
    [InsurenceNotes] [varchar](100) NULL,
    [PropertyInspection] [tinyint] NULL,
    [PropertyInspectionDate] [date] NULL,
    [PropertyInspectionInMonths] [tinyint] NULL,
    [PropertyInspectionNotes] [varchar](100) NULL,
    [LandLordRegistration] [tinyint] NULL,
    [LandLordRegistrationExpiryDate] [date] NULL,
    [LandlordRegistrationNo] [varchar](20) NULL,
    [LandlordRegistrationNotes] [varchar](100) NULL,
    [NextRentReview] [tinyint] NULL,
    [NextRentReviewExpiryDate] [date] NULL,
    [NextRentreviewNotes] [varchar](100) NULL,
    [ManagementFeeReview] [tinyint] NULL,
    [ManagementExpiryDate] [date] NULL,
    [ManagementfeeReviewNotes] [varchar](100) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

1 个答案:

答案 0 :(得分:0)

我同意,它看起来也像我一样。您尚未发布PropertyExpiries表的架构,但我假设您已检查其中一个日期列是否未定义为tinyint?

在这种情况下,我使用SQL Server Profiler捕获完全客户端针对SQL Server执行的操作然后尝试在SSMS中运行查询 - 至少你应该更好地了解哪个在执行中指出不匹配正在发生。