感谢您花时间查看并帮助我。我对似乎非常简单的插入操作感到疯狂,但我似乎无法通过这部分。这是我的代码:
protected void InsertIntoMaterialDB()
{
ToroGeneral toro = new ToroGeneral();
// Grab connection string.
string conString = toro.GetOracle1ConnectionString();
string insertQuery = "INSERT INTO MATERIALMOVEREQUEST (ORIGINATOR, REQUESTDATE, PARTNUMBER, REQUESTQTY, MOVEFROM, MOVETO, COMPLETEDBY, COMPLETION_DATE, COMMENTS, RESPONSETIME) "
+ "values (:Originator, :RequestDate, :PartNumber, :RequestQty, :MoveFrom, :MoveTo, :CompletedBy, :CompletionDate, :ResponseTime, :Comments)";
using(OracleConnection conn1 = new OracleConnection(conString))
{
conn1.Open();
OracleCommand cmd = conn1.CreateCommand();
OracleTransaction myTrans;
cmd.CommandText = insertQuery;
myTrans = conn1.BeginTransaction(IsolationLevel.ReadCommitted);
cmd.Transaction = myTrans;
if (cmd.Connection.State == ConnectionState.Closed)
{
cmd.Connection.Open();
}
DateTime rDate = DateTime.Parse(RequestDateTB.Text);
DateTime cDate = DateTime.Parse(CompDateTB.Text);
cmd.Parameters.AddWithValue("Originator", OracleType.VarChar).Value = OriginatorTB.Text;
cmd.Parameters.AddWithValue("RequestDate", OracleType.DateTime).Value = rDate;
cmd.Parameters.AddWithValue("PartNumber", OracleType.VarChar).Value = PartNumber.Text;
cmd.Parameters.AddWithValue("RequestQty", OracleType.Number).Value = Convert.ToInt32(RequestQuantity.Text);
cmd.Parameters.AddWithValue("MoveFrom", OracleType.VarChar).Value = MoveFromTB.Text;
cmd.Parameters.AddWithValue("MoveTo", OracleType.VarChar).Value = MoveToTB.Text;
cmd.Parameters.AddWithValue("CompletedBy", OracleType.VarChar).Value = CompletedByTB.Text;
cmd.Parameters.AddWithValue("CompletionDate", OracleType.DateTime).Value = cDate;
cmd.Parameters.AddWithValue("ResponseTime", OracleType.Number).Value = Convert.ToInt32(RespTimeTB.Text);
cmd.Parameters.AddWithValue("Comments", OracleType.VarChar).Value = CommentsTB.Text;
cmd.ExecuteNonQuery(); // THIS THROWS AN EXCEPTION.
cmd.Transaction.Commit();
}
}
除了两个“日期”类型字段 REQUESTDATE 和 COMPLETION_DATE 之外,我能够让一切正常工作。我不知道我做错了什么,除了当它到达 ExecuteNonQuery() 调用时它会引发异常。
如果有人有任何建议,将不胜感激。