2

当我将文本框更改为 datetimepicker 时出现此错误

这是我的代码

        Dim cmd As SqlCommand = sqlconn.CreateCommand
        sqlconn.Open()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "AddOfficeEquipmentProfile"
        cmd.Parameters("@OE_PurchaseDate").Value = dtpPurchaseDate.Value
        cmd.ExecuteNonQuery()
        sqlconn.close

这是我的存储过程如下

CREATE PROCEDURE AddOfficeEquipmentProfile
(

@OE_PurchaseDate    smalldatetime,      

)
AS

INSERT INTO tblOfficeEquipmentProfile (OE_PurchaseDate) 
VALUES (@OE_PurchaseDate)
GO
4

1 回答 1

4

我认为错误消息非常简单。您需要在尝试设置其值之前添加参数。

cmd.CommandText = "AddOfficeEquipmentProfile"
cmd.Parameters.Add("@OE_PurchaseDate",SqlDbType.SmallDateTime)
cmd.Parameters("@OE_PurchaseDate").Value = dtpPurchaseDate.Value
于 2013-05-03T07:58:25.257 回答