asp.net中IDataParameter调用存储过程的实现方法

本文实例讲述了asp.net中IDataParameter调用存储过程的实现方法,是asp.net数据库程序设计中非常实用的技巧。分享给大家供大家参考。

具体实现方法如下:

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> /// 执行存储过程,返回影响的行数 /// </summary> /// <param>存储过程名</param> /// <param>存储过程参数</param> /// <param>影响的行数</param> /// <param>返回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; } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzgfp.html