List<SqlParameter> paramArray = new List<SqlParameter>();//申明一个集合
paramArray.Add(new SqlParameter("@MeterNumber", MeterNumber));//输入参数
paramArray.Add(new SqlParameter("@LastMeterPointer", LastMeterPointer));//输入参数
paramArray.Add(new SqlParameter("@ThisMeterPointer", ThisMeterPointer));//输入参数
paramArray.Add(new SqlParameter("@ChargeDate", time));//输入参数
SqlParameter sqlParm4 = new SqlParameter("@GasUserID_EX", SqlDbType.VarChar, 50);
sqlParm4.Direction = ParameterDirection.Output;//输出参数
SqlParameter sqlParm5 = new SqlParameter("@CurrentPrice", SqlDbType.VarChar, 50);
sqlParm5.Direction = ParameterDirection.Output;//输出参数
SqlParameter sqlParm6 = new SqlParameter("@Syl", SqlDbType.VarChar, 50);
sqlParm6.Direction = ParameterDirection.Output;//输出参数
SqlParameter sqlParm7 = new SqlParameter("@RetGasUserID", SqlDbType.VarChar, 50);
sqlParm7.Direction = ParameterDirection.Output;//输出参数
paramArray.Add(sqlParm4);
paramArray.Add(sqlParm5);
paramArray.Add(sqlParm6);
paramArray.Add(sqlParm7);
try
{
db(上下文类).Database.ExecuteSqlCommand("EXEC [XAO_Meter_InsertChaoBiao] @MeterNumber,@LastMeterPointer,@ThisMeterPointer,@ChargeDate,@GasUserID_EX out,@CurrentPrice out,@Syl out,@RetGasUserID out", paramArray.ToArray());
}
catch (System.Data.Entity.Validation.DbEntityValidationException ex)//捕获异常
{
var msg = string.Empty;
var errors = (from u1 in ex.EntityValidationErrors select u1.ValidationErrors).ToList();
foreach (var item1 in errors)
msg += item1.FirstOrDefault().ErrorMessage;
Common.writeLog(msg, "异常数据", "");//记录日志文件
throw;
}
string gasuserid = paramArray[4].Value.ToString();
string currenprice = paramArray[5].Value.ToString();
price = currenprice;
string syl = paramArray[6].Value.ToString();
yue = syl;
string retgasUserID = paramArray[7].Value.ToString();//取值
paramArray.Add(new SqlParameter("@MeterNumber", MeterNumber));//输入参数
paramArray.Add(new SqlParameter("@LastMeterPointer", LastMeterPointer));//输入参数
paramArray.Add(new SqlParameter("@ThisMeterPointer", ThisMeterPointer));//输入参数
paramArray.Add(new SqlParameter("@ChargeDate", time));//输入参数
SqlParameter sqlParm4 = new SqlParameter("@GasUserID_EX", SqlDbType.VarChar, 50);
sqlParm4.Direction = ParameterDirection.Output;//输出参数
SqlParameter sqlParm5 = new SqlParameter("@CurrentPrice", SqlDbType.VarChar, 50);
sqlParm5.Direction = ParameterDirection.Output;//输出参数
SqlParameter sqlParm6 = new SqlParameter("@Syl", SqlDbType.VarChar, 50);
sqlParm6.Direction = ParameterDirection.Output;//输出参数
SqlParameter sqlParm7 = new SqlParameter("@RetGasUserID", SqlDbType.VarChar, 50);
sqlParm7.Direction = ParameterDirection.Output;//输出参数
paramArray.Add(sqlParm4);
paramArray.Add(sqlParm5);
paramArray.Add(sqlParm6);
paramArray.Add(sqlParm7);
try
{
db(上下文类).Database.ExecuteSqlCommand("EXEC [XAO_Meter_InsertChaoBiao] @MeterNumber,@LastMeterPointer,@ThisMeterPointer,@ChargeDate,@GasUserID_EX out,@CurrentPrice out,@Syl out,@RetGasUserID out", paramArray.ToArray());
}
catch (System.Data.Entity.Validation.DbEntityValidationException ex)//捕获异常
{
var msg = string.Empty;
var errors = (from u1 in ex.EntityValidationErrors select u1.ValidationErrors).ToList();
foreach (var item1 in errors)
msg += item1.FirstOrDefault().ErrorMessage;
Common.writeLog(msg, "异常数据", "");//记录日志文件
throw;
}
string gasuserid = paramArray[4].Value.ToString();
string currenprice = paramArray[5].Value.ToString();
price = currenprice;
string syl = paramArray[6].Value.ToString();
yue = syl;
string retgasUserID = paramArray[7].Value.ToString();//取值