本文實(shí)例講述了asp.net中IDataParameter調(diào)用存儲(chǔ)過(guò)程的實(shí)現(xiàn)方法,是asp.net數(shù)據(jù)庫(kù)程序設(shè)計(jì)中非常實(shí)用的技巧。分享給大家供大家參考。
public string GenerateExamePaper(string paperType, string driverID, string MacAddr)
{
int i;
IDataParameter[] iData = new SqlParameter[4];
iData[0] = new SqlParameter("@paperType", paperType);
iData[1] = new SqlParameter("@driverID", driverID);
iData[2] = new SqlParameter("@MacAddr", MacAddr);
iData[3] = new SqlParameter("@sReturn", SqlDbType.Char, 50, ParameterDirection.Output, false, 0, 0, string.Empty, DataRowVersion.Default,null);
string aaa = "";
i= DbHelperSQL.RunProcedureParOut("Pro_GenerateExamePaper", iData, out aaa).ToString();
return aaa;
}
/// summary>
/// 執(zhí)行存儲(chǔ)過(guò)程,返回影響的行數(shù)
/// /summary>
/// param name="storedProcName">存儲(chǔ)過(guò)程名/param>
/// param name="parameters">存儲(chǔ)過(guò)程參數(shù)/param>
/// param name="rowsAffected">影響的行數(shù)/param>
/// param name="rowsAffected">返回output值/param>
/// returns>/returns>
public static int RunProcedure(string storedProcName, IDataParameter[] parameters, out int rowsAffected,out str)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
int result;
connection.Open();
SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);
rowsAffected = command.ExecuteNonQuery();
result = (int)command.Parameters["ReturnValue"].Value;
str= (int)command.Parameters["@sReturn"].Value;
return result;
}
}