是c#里执行存储过程的一个方法,由于参数比较多,特别是后面那一段
parameters[x].Direction =ParameterDirection.Output;感觉很冗余,但必须要写,最好能写在 new SqlParameter()实例化里,但这个重载虽然最后参数可以写Direction ,但是那个重载必须有7个参数,很多是我不需要的,想请教大侠一般是怎么写的,非常感谢。
- C# code
public static string getMyAndRoom(int id,string guidkey,int jRoomId) { string p_name = "getMyAndRoom"; SqlParameter[] parameters = { new SqlParameter("@id", id), new SqlParameter("@guidkey",guidkey), new SqlParameter("@jRoomId",jRoomId), new SqlParameter("@userName",SqlDbType.NVarChar,30), new SqlParameter("@qqImg",SqlDbType.VarChar,600), new SqlParameter("@roomName",SqlDbType.NVarChar,30), new SqlParameter("@bgImg",SqlDbType.VarChar,360), new SqlParameter("@sex",SqlDbType.Bit), new SqlParameter("@jRoomName",SqlDbType.NVarChar,30), new SqlParameter("@jRoomBgImg",SqlDbType.VarChar,360), new SqlParameter("@jRoomqqImg",SqlDbType.VarChar,200)}; parameters[3].Direction = ParameterDirection.Output; parameters[4].Direction = ParameterDirection.Output; parameters[5].Direction = ParameterDirection.Output; parameters[6].Direction = ParameterDirection.Output; parameters[7].Direction = ParameterDirection.Output; parameters[8].Direction = ParameterDirection.Output; parameters[9].Direction = ParameterDirection.Output; parameters[10].Direction = ParameterDirection.Output; DataSet ds = DbHelperSQL.RunProcedure(p_name, parameters, "getMyAndRoom"); if (id != 0)
------解决方案--------------------
SqlParameter 构造函数中的第六个重载形式……
- C# code
public SqlParameter( string parameterName, SqlDbType dbType, int size, ParameterDirection direction, bool isNullable, byte precision, byte scale, string sourceColumn, DataRowVersion sourceVersion, Object value)