明明写了参数,确始终提示 过程需要参数,但未提供该参数SqlDataReade
public SqlDataReader SqlDataReader(string storedProcedure, params SqlParameter[] sp) { SqlCommand cmd = new SqlCommand(storedProcedure, this.Conn); if (sp != null && sp.Length > 0) { cmd.Parameters.AddRange(sp); } try { this.Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);//执行之后关闭连接 commonclass.MsgOk(Conn.State.ToString()); return dr; } catch (SqlException er) { this.Conn.Close(); throw er; } }
上面代码,死活提示,过程需要参数,但未提供该参数。准备放弃,使用dataset的时候,突破发现
没有指定 cmd.CommandType 加上这句搞定。
cmd.CommandType = CommandType.StoredProcedure;
public SqlDataReader SqlDataReader(string storedProcedure, params SqlParameter[] sp) { SqlCommand cmd = new SqlCommand(storedProcedure, this.Conn); cmd.CommandType = CommandType.StoredProcedure; if (sp != null && sp.Length > 0) { cmd.Parameters.AddRange(sp); } try { this.Conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);//执行之后关闭连接 commonclass.MsgOk(Conn.State.ToString()); return dr; } catch (SqlException er) { this.Conn.Close(); throw er; } }