明明写了参数,确始终提示 过程需要参数,但未提供该参数SqlDataReade

it2022-05-06  0

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; } }

  

 

 

转载于:https://www.cnblogs.com/bantongshui/archive/2012/12/20/3170009.html

相关资源:DirectX修复工具V4.0增强版

最新回复(0)