【问题标题】:Conversion failed because the DateTime data value overflowed the type specified for the DateTime value part in the consumer's buffer转换失败,因为 DateTime 数据值溢出了为使用者缓冲区中的 DateTime 值部分指定的类型
【发布时间】:2019-12-23 19:40:40
【问题描述】:

我在 Sybase ASE 中有一个带有日期参数的存储过程,所以当我创建一个 OLE DB 连接并将日期参数传递给 OLE DB 命令时,我们正在映射到具有 OLEDBType.DBTimeStamp 类型的参数,日期时间存储过程中的参数类型是 smalldatetime。 这是示例代码。

OLEDBConnection  con = new OLEDBConnection(connectionstring);
con.open;

OLEDBCommand cmd = new OLEDBCommand(con);
cmd.QueryString = "dbo.job_xb_new"
cmd.QueryType = "Stored Procedure";

cmd.Parameters.Add("@signoff",OLEType.DBTimeStamp);
cmd.Parameters("@signoff").Value = Datetime.now;

cmd.executeNonQuery(); -----------> ERROR HERE

在执行存储过程时,我收到错误消息。 “转换失败,因为 DateTime 数据值溢出了为消费者缓冲区中的 DateTime 值部分指定的类型”? 请帮忙!!!

【问题讨论】:

  • 传递给数据库的实际值是多少?

标签: oledb sap-ase oledbconnection oledbcommand sybase-ase15


【解决方案1】:

根据给出的唯一信息,可能会有解决方案可供尝试。

  1. 将输入值的数据类型更改为存储过程为 char/varchar
create procedure dbo.myProc
@inDate varchar(20)
AS
BEGIN
..

END
  1. 在传递给您的查询之前使用 CONVERT 执行内部转换。
SET @inDate = CONVERT(datetime,@inDate,[style parameter number])
  1. 对于故障排除,只需注释掉过程中的所有内容并首先选择 @inDate 以确定来自 OLE DB 应用程序的数据是什么样的。你可能会在那里大吃一惊……

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    相关资源
    最近更新 更多