0
很基本的sql命令。只是想從我正在循環的不同表中獲得計數。但是,如果我改變sqlCommand並添加';'最後我得到異常,SQL命令沒有正確結束。SQL命令沒有正確結束異常
sqlCommand = String.Format("SELECT COUNT(1) FROM SO.{0} where DR_ADDRESS_ID = {1};", table, drAddr);
我很好奇爲什麼這個分號讓這個異常拋出,因爲命令是以';'結尾的,
sqlCommand = String.Format("SELECT COUNT(1) FROM SO.{0} where DR_ADDRESS_ID = {1}", table, drAddr);
try
{
using(OracleCommand ocCommand = new OracleCommand(sqlCommand,CommandType.Text))
{
ocCommand.Connection = dbConnection;
recordCounter = Convert.ToInt64(ocCommand.ExecuteScalar());
}
}
catch (Exception er)
{
MessageBox.Show(String.Format("Error in RecordCount for table {0}: Reference {1} for log. err = {2}",table, logFilePath,er.ToString()));
recordCounter = -1;
using (StreamWriter writer = new StreamWriter(logFilePath, true))
{
writer.WriteLine(String.Format("Table: {0}. Command {1}", table,sqlCommand.ToString()));
}
}
您正在使用哪種數據庫產品?可能不是MySQL,Oracle和SQL Server。請修改標籤以僅保留相關的標籤。 – mathguy
基於代碼和錯誤消息,我刪除了不相關的標籤。 –
@mathguy我的道歉,Oracle數據庫是db產品。 – Korey