2
我想執行一個查詢,但我們面對的連接字符串的問題ASP.NET:連接被關閉
這是我的代碼:
OracleCommand _commandInvoice = new OracleCommand();
_commandInvoice.CommandType = CommandType.StoredProcedure;
_commandInvoice.Parameters.AddWithValue("I_INVOICE_ID", strInvoiceID);
_commandInvoice.Parameters.AddWithValue("I_ORG_ID", ORG_ID);
_commandInvoice.Parameters.AddWithValue("I_ORG_NAME", strOrg_name);
_commandInvoice.Parameters.AddWithValue("I_PROJECT", strProject);
_commandInvoice.Parameters.AddWithValue("I_VENDOR_NAME", strVendor_name);
_commandInvoice.Parameters.AddWithValue("I_VENDOR_TYPE_LOOKUP_CODE", strVendorType_lookup_Code);
_commandInvoice.Parameters.AddWithValue("I_INVOICE_NUMBER", strInvoice_number);
_commandInvoice.Parameters.AddWithValue("I_INVOICE_DATE", strInvoice_date);
_commandInvoice.Parameters.AddWithValue("I_INVOICE_AMT", strInvoice_Amt);
_commandInvoice.Parameters.AddWithValue("I_OUTSTANDING_AMT", strOutstanding_Amt);
_commandInvoice.Parameters.AddWithValue("I_OUTSTANDING_REQ_AMT", strOutstanding_req_amt);
if (obj_Conn.State == ConnectionState.Closed)
{
obj_Conn.Open();
_commandInvoice.ExecuteNonQuery();
}
我們越來越上午錯誤:
Invalid operation. The connection is closed.
你應該[我們已經能夠停止使用AddWithValue()?]退房(http://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using- addwithvalue-already /)並停止使用'.AddWithValue()' - 它可能會導致意想不到的和令人驚訝的結果... –
而且您還需要**定義**存儲過程名稱**,以便您的命令知道*哪個*存儲過程執行!我建議在構造函數中這樣做(並設置連接):'OracleCommand _commandInvoice = new OracleCommand(「storedProcedureName」,obj_Conn);' –