当我运行以下代码" ORA-01008时:并非所有变量都绑定了#34;正在显示。 Wile调试我可以在这个语句中看到@Number的值 - > " ParameterDirection.Input,@ NUMBER" 。但正在显示执行错误。
DB_Common _dbCommon = new DB_Common();
DbConnection conn2 = _dataFactory.CreateConnection();
DbCommand cmd1 = _dataFactory.CreateCommand();
conn2.ConnectionString = ABC.AppSettings ["ORACnnStr_HOSPITAL"];
conn2.Open();
cmd1.Connection = conn2;
cmd1.Transaction = trans;
cmd1.CommandText = OracleHelper.FixCommandText("INSERT INTO NBTABLE(NUMBER) VALUES(@NUMBER) ");
cmd1.CommandType = CommandType.Text;
DbParameter param2 = null;
foreach (DataRow dr2 in _DTF_SPE.Rows)
{
cmd1.Parameters.Clear();
OracleHelper.CreateParameter(ref cmd, ref param, "@NUMBER", DbType.String, ParameterDirection.Input, @NUMBER);
cmd1.ExecuteNonQuery();
cmd1.Dispose();
}
}
trans.Commit();
}
修改
更新了如下代码。在开始使用conn2之前,@ doctor的值取自conn1.conn1。 ORA-01008:并非所有变量绑定都在执行时显示。
DB_Common _dbCommon = new DB_Common();
DbConnection conn2 = _dataFactory.CreateConnection();
DbCommand cmd1 = _dataFactory.CreateCommand();
conn2.ConnectionString = SCC.AppSettings["ORACnnStr_abc"];
conn2.Open();
cmd1.Connection = conn2;
cmd1.Transaction = trans;
cmd1.CommandText = OracleHelper.FixCommandText("INSERT INTO numbertable(Doctor,PART,CODE) VALUES(@doctor,'K','G') ");
cmd1.CommandType = CommandType.Text;
DbParameter param2 = null;
cmd1.Parameters.Clear();
cmd1.ExecuteNonQuery();
cmd1.Dispose();
答案 0 :(得分:0)
使用分号:
格式代替@
格式
"INSERT INTO NBTABLE(NUMBER) VALUES(:NUMBER_) "
您最好提供NUMBER_
(关键字)以外的名称(如NUMBER
)。
再次致电@
:
OracleHelper.CreateParameter(ref cmd, ref param, "NUMBER_",....