C# web服务和执行方法中存在错误
我用下面的execute方法编写了这个web服务。我希望您能帮助解决我在“打开”和“关闭”中遇到的此错误: System.Data.SqlClient.SqlConnection不包含“open”的定义,也不包含异常方法“open”,但可以找到第一种类型的参数System.Data.SqlClient.SqlConnection除外 我必须在代码中更改什么?我认为在中返回这个.ExecuteQuery(orderItem,conn)这是我的假释问题C# web服务和执行方法中存在错误,c#,asp.net,web-services,C#,Asp.net,Web Services,我用下面的execute方法编写了这个web服务。我希望您能帮助解决我在“打开”和“关闭”中遇到的此错误: System.Data.SqlClient.SqlConnection不包含“open”的定义,也不包含异常方法“open”,但可以找到第一种类型的参数System.Data.SqlClient.SqlConnection除外 我必须在代码中更改什么?我认为在中返回这个.ExecuteQuery(orderItem,conn)
[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();
}
}
尝试conn.Open()代码>而不是连接打开()代码>和连接关闭()代码>而不是连接关闭()代码>键入conn.Open()
而不是conn.Open()代码>和连接关闭()
而不是连接关闭()代码>你应该没事。这在执行查询方法中。C#是区分大小写的语言。“无例外方法”?“例外”?这是实际错误还是键入错误?在诊断问题时,您可能希望养成复制和粘贴准确错误消息的习惯。信息中使用的术语非常有用。