62,074
社区成员
发帖
与我相关
我的任务
分享
int OrdersDetailID = 463;
decimal NormProcessCost = (decimal)51.1;
decimal NormPrice = (decimal)60.94;
float NormScaleModel = (float)-75.59;
string ConnectionString = "server=192.168.1.127;uid=sa;pwd=123456;database=Data";
SqlConnection myConnection = new SqlConnection(ConnectionString); //定义数据库的Connection and Command
SqlCommand myCommand = new SqlCommand("[Sales].[Update_OrdersDetail_Norm]", myConnection); //定义使用的存储过程名称
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("@OrdersDetailID", SqlDbType.Int));
myCommand.Parameters["@OrdersDetailID"].Value = OrdersDetailID;
myCommand.Parameters.Add(new SqlParameter("@NormProcessCost", SqlDbType.Decimal));
myCommand.Parameters["@NormProcessCost"].Value = NormProcessCost;
myCommand.Parameters.Add(new SqlParameter("@NormPrice", SqlDbType.Decimal));
myCommand.Parameters["@NormPrice"].Value = NormPrice;
myCommand.Parameters.Add(new SqlParameter("@NormScaleModel", SqlDbType.Float));
myCommand.Parameters["@NormScaleModel"].Value = NormScaleModel;
myCommand.Parameters.AddWithValue("@RETURN_VALUE", "").Direction = ParameterDirection.ReturnValue;
int ok = 0;
try
{ ///打开数据库的连接
myConnection.Open();
}
catch (Exception ex)
{
throw new Exception("数据库连接失败!", ex);
}
try
{ ///执行数据库的存储过程(访问数据库)
SqlDataReader OrderDr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
ok = (int)myCommand.Parameters["@RETURN_VALUE"].Value;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
myConnection.Close();
}