没有企业数据库中的代码,我使用下面的代码中插入一些东西DB和读取返回值从企业库重写,以保存数据并返回值
int result = 0;
using (SqlConnection myConnection =
new SqlConnection(AppConfiguration.ConnectionString))
{
SqlCommand myCommand = new SqlCommand("SaveUser", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.AddWithValue("@location", objUser.Location);
DbParameter returnValue;
returnValue = myCommand.CreateParameter();
returnValue.Direction = ParameterDirection.ReturnValue;
myCommand.Parameters.Add(returnValue);
myConnection.Open();
myCommand.ExecuteNonQuery();
result = Convert.ToInt32(returnValue.Value);
myConnection.Close();
}
我该怎么办了在企业数据库中是一样的吗?我想从正在调用的存储过程中返回值。
不适用于我。当我尝试获取“returnValue”参数的值时,抛出IndexOutOfRangeException。 – HiveHicks 2011-07-26 12:29:37
这被标记为答案,但你有没有得到这个工作?我正在做类似的事情,但试图检索一个out参数。这是我的问题:http://stackoverflow.com/questions/39985999/microsoft-practices-enterpriselibrary-data-database-addout-parameter-not-getting – ptn77 2016-10-21 17:17:04