所以这是我得到的错误:ORA-01036:非法变量名称/编号
我所做的只是尝试用这些值更新表格。这些值不为空,并且参数中的每个变量都有值。
查询在 Oracle 中执行良好(没有参数),但是当我添加参数时,它给出了 ORA-01036:非法变量名称/编号。
我几乎尝试了一切,但没有运气!
using (OracleConnection con = new OracleConnection(cs))
{
const string query =
@"UPDATE ASSOCIATED_CENTERS_INFO
SET DIS_ASSOCIATED_BY = (SELECT ID FROM VC_ADMINISTRATORS WHERE USERNAME = ':USER'),
DIS_ASSOCIATION_DATE = SYSDATE,
ACTIVE_YN = 'N',
NOTES = CONCAT(NOTES, '<br>' || SYSDATE || ' ' || (SELECT FIRSTNAME || ',' || LASTNAME FROM VC_ADMINISTRATORS WHERE USERNAME = ':USER') || ': ' || ':COMMENT')
WHERE OSC_ID = :OSCID AND ASSOCIATED_OSC_ID = :ASSOCIATEDOSCID;";
OracleCommand cmd = new OracleCommand(query, con);
cmd.CommandType=CommandType.Text;
cmd.Parameters.AddWithValue(":USER", userName);
cmd.Parameters.AddWithValue(":COMMENT", comment);
cmd.Parameters.AddWithValue(":OSCID", selectedIdOnMap);
cmd.Parameters.AddWithValue(":ASSOCIATEDOSCID", selectedIdOnListBox);
con.Open();
cmd.ExecuteNonQuery();
}