0

我正在为移动扫描仪开发入站应用程序。此应用程序将直接更新到我们的主数据库。但是我在保存和调用日期时间值时遇到问题。

首先,我想将日期保存为dd-mmm-yyyy日期时间字段,并将时间保存为日期时间hh:mm字段。我收到错误说明“转换日期时间值的算术溢出错误

这是我的代码:

cmd = New SqlCeCommand("insert into Receiving (Id,PalletNo,Batch,Run,PCode,Qty,AddUser,AddDate) VALUES (@Id,@PalletNo,@Batch,@Run,@PCode,@Qty,@AddUser,@AddDate)", cn)
cmd.Parameters.AddWithValue("@PalletNo", txtPallet.Text)
cmd.Parameters.AddWithValue("@Batch", Trim(txtBatch.Text))
cmd.Parameters.AddWithValue("@Run", Trim(txtRun.Text))
cmd.Parameters.AddWithValue("@PCode", Trim(txtPCode.Text))
cmd.Parameters.AddWithValue("@Qty", Val(txtQty.Text))
cmd.Parameters.AddWithValue("@AddUser", txtEmpNo.Text)
cmd.Parameters.AddWithValue("@Id", (ID + 1))
cmd.Parameters.AddWithValue("@AddDate", Format(Now, "dd-mmm-yyyy"))
cmd.ExecuteNonQuery()
4

1 回答 1

0

您不能以任何格式将日期时间值存储在数据库中。只需存储它并在检索值时为它们提供所需的格式。

如果您使用的是 SQL Server,手动插入日期的格式是MM/dd/yyyy,但在您的情况下,您可以简单地使用 SQL 函数getdate()来获取实际的日期时间。

于 2013-04-17T07:44:42.863 回答