我使用以下執行方法編寫了此Web服務。我希望你們對我在打開和關閉時出現的這個錯誤有所幫助:網絡服務中的錯誤和執行方法
System.Data.SqlClient.SqlConnection不包含'open'的定義,並且沒有第一種類型的'open'異常方法'open' ?的說法System.Data.SqlClient.SqlConnection可以發現
我必須在我的代碼改變我認爲,在回報this.ExecuteQuery(OrderItem的,康恩);是我paroblem
[WebMethod(Description = "This will input computers into the database", EnableSession = false)]
public string orderItem(int CUS_ID, string COM_ID, int Quantity,double COMPrice)
{
try
{
dbConn = new DbConnection();
SqlConnection conn = dbConn.OpenConnection();
SqlCommand orderItem = new SqlCommand("OrderComputer", conn);
orderItem.CommandType = CommandType.StoredProcedure;
SqlParameter add_CUS_ID = orderItem.Parameters.Add("@CUS_ID", SqlDbType.Int, 4);
add_CUS_ID.Value = CUS_ID;
SqlParameter addBK_ISBN = orderItem.Parameters.Add("@COM_ID", SqlDbType.Char, 80);
addBK_ISBN.Value = COM_ID;
SqlParameter add_Quantity = orderItem.Parameters.Add("@Quantity", SqlDbType.Int, 2);
add_Quantity.Value = Quantity;
SqlParameter add_COMPrice = orderItem.Parameters.Add("@COMPrice", SqlDbType.Money, 8);
add_COMPrice.Value = COMPrice;
return this.ExecuteQuery(orderItem,conn);
}
catch (Exception e)
{
return e.ToString();
}
}
的執行:
protected string ExecuteQuery(SqlCommand QueryObject, SqlConnection conn)
{
try
{
conn.open();
int queryResult = QueryObject.ExecuteNonQuery();
if (queryResult != 0) {
return "Your request is CORRECT";
}
else
{
return "error: QueryResult= " + queryResult;
}
}
finally
{
conn.close();
}
}
「沒有例外的方法」? 「除外」?這是實際的錯誤還是你輸入錯誤?診斷問題時,您可能需要養成複製並粘貼確切錯誤信息的習慣。消息中使用的術語可能非常有用。 – David