使用 c# 在 Oracle Table 中为时间戳列添加日期
Add Date in Oracle Table for TimeStamp Column using c#
我已经编写代码将日期添加到 oracle table 中,列类型为 'TimeStamp'
但我收到
的错误
'ORA-01843: not a valid month', my code is below, column in oracle DB
of type 'Timestamp', trying to update the column with c#,
DateTime dt =
DateTime.Parse(Convert.ToString(CurrentItem[SharePointColumnInternal[j]]));
dt = dt.ToLocalTime();
UpdateCmd += i + "=" + "'" + dt + "'" + ",";
这是我构建的更新命令字符串:UpdateCmd
并在 C# 代码中执行。
您不应该通过连接字符串来构建 SQL 命令;这不仅难度更大,而且对SQL注入开放。
看看使用参数化查询,例如:
DateTime dt = DateTime.Parse(Convert.ToString(CurrentItem[SharePointColumnInternal[j]]));
dt = dt.ToLocalTime();
using (var connection = new OracleConnection("YourConnectionString"))
using (var command = new OracleCommand("UPDATE YourTable SET YourDateTimeColumn = :dt Where ...", connection))
{
command.Parameters.Add("dt", dt);
command.ExecuteNonQuery();
}
我已经编写代码将日期添加到 oracle table 中,列类型为 'TimeStamp' 但我收到
的错误'ORA-01843: not a valid month', my code is below, column in oracle DB of type 'Timestamp', trying to update the column with c#,
DateTime dt =
DateTime.Parse(Convert.ToString(CurrentItem[SharePointColumnInternal[j]]));
dt = dt.ToLocalTime();
UpdateCmd += i + "=" + "'" + dt + "'" + ",";
这是我构建的更新命令字符串:UpdateCmd 并在 C# 代码中执行。
您不应该通过连接字符串来构建 SQL 命令;这不仅难度更大,而且对SQL注入开放。
看看使用参数化查询,例如:
DateTime dt = DateTime.Parse(Convert.ToString(CurrentItem[SharePointColumnInternal[j]]));
dt = dt.ToLocalTime();
using (var connection = new OracleConnection("YourConnectionString"))
using (var command = new OracleCommand("UPDATE YourTable SET YourDateTimeColumn = :dt Where ...", connection))
{
command.Parameters.Add("dt", dt);
command.ExecuteNonQuery();
}