一般的なサーバに保持されているテーブルから取得したSQLコマンドにパラメータを追加する方法として、コードに準備済みのステムを実装しようとしています。私はそれを正しくするように見えることはできません。私は次のエラーを取得する:文の問題を準備する
ORA-00936: missing expression
ORA-00936: missing expression
Prepare Statement: select VALUE from RWOL_CONFIGURATION where ID = @ItemId
私の推測では、それだけで値を置き換えるのではなく、私は私が行方不明です何を知らないということです。
私は、次のような結果を得るために努力しています。私は、私のオブジェクトを作成し、データベースに私たちのテーブルからクエリ文字列を取得するには、コマンドにそれを追加し、リストオブジェクトにパラメータを追加して、それをすべて一緒にネクタイしてクエリを実行するために、以下に示す最後のメソッドを使用します。
を//This function gets me a config item from the database
private string GetConfigurationItem(string itemId)
{
//new database connection object
OleDataBaseConnection oleDataBaseConnection = new OleDataBaseConnection();
//todo get this query from the sql factory
SqlFactory sqlFactory = new SqlFactory();
//This method gets the query string from the database
string sqlQuery = sqlFactory.GetQueryString("GET_CONFIGURATION_ITEM", m_dialect);
if (!String.IsNullOrEmpty(sqlQuery))
{
//add parameter to list
oleDataBaseConnection.AddStoredProcedureParameter("@ItemId", itemId);
//execute the sql command after adding the parameters to the command
oleDataBaseConnection.OleExecutePrepareStatementWithParametersQuery(sqlQuery);
string returnValue = oleDataBaseConnection.NextRecord() ? oleDataBaseConnection.GetFieldById(0) : "Error";
oleDataBaseConnection.Close();
return returnValue;
}
else
{
return "ERROR";
}
}
//adds the parameters to list objects ready for the next method
public void AddParameter(string parameter, object value)
{
m_parameterName.Add(parameter);
m_parameterValue.Add(value);
} // End of void AddParameter()
/// <summary>
/// Executes a command with the parameters passed to AddParameter(parameterName, parameterValue) and creates a recordset.
/// </summary>
///
/// <param name="commandName">The name of the stored procedure to execute.</param>
public bool OleExecutePrepareStatementWithParametersQuery(string commandName)
{
if (String.IsNullOrEmpty(commandName))
{
return false;
}
try
{
PrepareConnection();
m_oleDatabaseCommand.CommandText = commandName;
m_oleDatabaseCommand.CommandType = CommandType.StoredProcedure;
if (m_storedProcedureParameterName.Count != 0)
{
for (int i = 0; i < m_storedProcedureParameterName.Count; i++)
{
m_oleDatabaseCommand.Parameters.AddWithValue(m_storedProcedureParameterName[i], m_storedProcedureParameterValue[i]);
}
m_storedProcedureParameterName.Clear();
m_storedProcedureParameterValue.Clear();
}
m_hasRecordSet = true;
m_oleDatabaseDataReader = m_oleDatabaseCommand.ExecuteReader();
return true;
}
catch (Exception ex)
{
if (QueueErrors)
{
QueuedErrorsList.AppendLine(ex.Message);
QueuedErrorsList.AppendLine("Prepare Statement: " + storedProcedureName);
QueuedErrorsList.AppendLine();
QueuedErrorCount++;
return false;
}
try
{
Close();
}
catch
{
}
throw new Exception(ex.Message + "\r\n\r\nPrepare Statement: " + storedProcedureName);
}
} // End of void OleExecutePrepareStatementWithParametersQuery()
申し訳ありませんがコードがたくさんありますが、それはかなり簡単で、私はそれが問題に役立つだろうと思った。
これが機能しなくなることは明らかですか?
'sqlQuery'の値を投稿してください。 – Oded
また、Oracleプロバイダの代わりにOleDbを使用しているのは何ですか? – Oded
Oracleデータベースを使用しているだけではありません。私たちは約6種類のデータベースを持ち、OLEは私たちのニーズに合っています。コマンドは異なるデータベース方言ごとに格納されており、必要なものを取得し、実行する前にいくつかのパラメータにパラメータを追加する必要があります。私は単純なString.Replace( "{0}"、itemId)を使いたいと思っていました。上司は私に、上記のようなものを使用することを望んでいます。代わりに、それが行われる通常の方法です。エラー・メッセージには、sqlQueryの値が表示されます。 – CSharpened