asp.net怎么实现这样执行存储过程: 'exec Proc_InsertShopCart '51','13','23','12.32'' ?
请教这么一个问题:asp.net如何传递多个值到存储过程?
我的一个存储过程想接受三个参数,但是我又不想多写代码,
原来是这样实现的:
public void AddShopCart(int P_Int_GoodsID, float P_Flt_MemberPrice, int P_Int_MemberID, float P_Flt_GoodsWeight)
{
SqlConnection myConn = dbObj.GetConnection();
SqlCommand myCmd = new SqlCommand("Proc_InsertShopCart", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
//添加参数
SqlParameter GoodsID = new SqlParameter("@GoodsID", SqlDbType.BigInt, 8);
GoodsID.Value = P_Int_GoodsID;
myCmd.Parameters.Add(GoodsID);
//添加参数
SqlParameter MemberPrice = new SqlParameter("@MemberPrice", SqlDbType.Float, 8);
MemberPrice.Value = P_Flt_MemberPrice;
myCmd.Parameters.Add(MemberPrice);
//添加参数
SqlParameter MemberID = new SqlParameter("@MemberID", SqlDbType.BigInt, 8);
MemberID.Value = P_Int_MemberID;
myCmd.Parameters.Add(MemberID);
//添加参数
SqlParameter GoodsWeight = new SqlParameter("@GoodsWeight", SqlDbType.Float , 8);
GoodsWeight.Value = P_Flt_GoodsWeight;
myCmd.Parameters.Add(GoodsWeight);
//执行过程
myConn.Open();
try
{
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
myCmd.Dispose();
myConn.Close();
}
这样是没有问题的,后来改成这样:
public void AddShopCart(int P_Int_GoodsID, float P_Flt_MemberPrice, int P_Int_MemberID, float P_Flt_GoodsWeight)
{
SqlConnection myConn = dbObj.GetConnection();
SqlCommand myCmd = new SqlCommand("exec Proc_InsertShopCart '"+P_Int_GoodsID+"','"+P_Flt_MemberPrice+"','"+P_Int_MemberID+"','"+P_Flt_GoodsWeight+"'", myConn);
myCmd.CommandType = CommandType.StoredProcedure;
myConn.Open();
try
{
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
myCmd.Dispose();
myConn.Close();
}
}
然后执行的时候就提示:
找不到存储过程 'exec Proc_InsertShopCart '51','13','23','12.32''。
请问这是怎么回事?