他在开发的时候都是使用的存储过程,我太笨了对存储过程就是不明白。所以改用sql语句,可是到了他的sqlhelp类里面呢参数好像又带了存储不知道怎么办了。还请大家指教:
一:/// <summary>
/// Execute a SqlCommand that returns a resultset against the database specified in the connection string
/// using the provided parameters.
/// </summary>
/// <res>
/// e.g.:
/// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </res>
/// <param name="cmdType">the CommandType (stored procedure, text, etc.)</param>
/// <param name="cmdText">the stored procedure name or T-SQL command</param>
/// <param name="cmdParms">an array of SqlParamters used to execute the command</param>
/// <returns>A SqlDataReader containing the results</returns>
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(CONN_STRING); // we use a try/catch here because if the method throws an exception we want to
// close the connection throw code, because no datareader will exist, hence the
// commandBehaviour.CloseConnection will not work
try
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
HttpContext.Current.Response.Write(cmd);
// HttpContext.Current.Response.Write();
HttpContext.Current.Response.End();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
{
conn.Close();
throw;
}
}说明了可以用sql语句的,前面我也已经改好了。
Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.Text, "select * from note_second_class",
new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@pageSize", AspNetPager1.PageSize));
Repeater1.DataBind();但是最后那两个 new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@pageSize", AspNetPager1.PageSize)似乎又是存储过程了。
上面我改的运行结果能显示,但是只是把全部数据都显示出来,没有按页次分了。谢谢大家~~
一:/// <summary>
/// Execute a SqlCommand that returns a resultset against the database specified in the connection string
/// using the provided parameters.
/// </summary>
/// <res>
/// e.g.:
/// SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
/// </res>
/// <param name="cmdType">the CommandType (stored procedure, text, etc.)</param>
/// <param name="cmdText">the stored procedure name or T-SQL command</param>
/// <param name="cmdParms">an array of SqlParamters used to execute the command</param>
/// <returns>A SqlDataReader containing the results</returns>
public static SqlDataReader ExecuteReader(CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection(CONN_STRING); // we use a try/catch here because if the method throws an exception we want to
// close the connection throw code, because no datareader will exist, hence the
// commandBehaviour.CloseConnection will not work
try
{
PrepareCommand(cmd, conn, null, cmdType, cmdText, cmdParms);
HttpContext.Current.Response.Write(cmd);
// HttpContext.Current.Response.Write();
HttpContext.Current.Response.End();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Parameters.Clear();
return rdr;
}
catch
{
conn.Close();
throw;
}
}说明了可以用sql语句的,前面我也已经改好了。
Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.Text, "select * from note_second_class",
new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@pageSize", AspNetPager1.PageSize));
Repeater1.DataBind();但是最后那两个 new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
new SqlParameter("@pageSize", AspNetPager1.PageSize)似乎又是存储过程了。
上面我改的运行结果能显示,但是只是把全部数据都显示出来,没有按页次分了。谢谢大家~~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货