내 문제는 내 사이트에 asp.net을 사용하고 있습니다. 도서 목록을 얻었고 모두 표시됩니다. 첫 번째 항목이 정렬되지리스트를 이용하여 내가 책 분류되지 않는이 코드를 실행할 때ASP.NET MySQL 주문 잘못된 결과 제공
public static IDataReader GetPageByCritere(
int pageNumber,
int pageSize,
out int totalPages,
string critere,
string direction)
{
int pageLowerBound = (pageSize * pageNumber) - pageSize;
totalPages = 1;
int totalRows = GetCount();
if (pageSize > 0) totalPages = totalRows/pageSize;
if (totalRows <= pageSize)
{
totalPages = 1;
}
else
{
int remainder;
Math.DivRem(totalRows, pageSize, out remainder);
if (remainder > 0)
{
totalPages += 1;
}
}
StringBuilder sqlCommand = new StringBuilder();
sqlCommand.Append("SELECT * ");
sqlCommand.Append("FROM a_book ");
//sqlCommand.Append("WHERE ");
sqlCommand.Append("ORDER BY ?Critere ?direction ");
sqlCommand.Append("LIMIT ?PageSize ");
if (pageNumber > 1)
{
sqlCommand.Append("OFFSET ?OffsetRows ");
}
sqlCommand.Append(";");
MySqlParameter[] arParams = new MySqlParameter[4];
arParams[0] = new MySqlParameter("?PageSize", MySqlDbType.Int32);
arParams[0].Direction = ParameterDirection.Input;
arParams[0].Value = pageSize;
arParams[1] = new MySqlParameter("?OffsetRows", MySqlDbType.Int32);
arParams[1].Direction = ParameterDirection.Input;
arParams[1].Value = pageLowerBound;
arParams[2] = new MySqlParameter("?Critere", MySqlDbType.VarChar, 50);
arParams[2].Direction = ParameterDirection.Input;
arParams[2].Value = critere;
arParams[3] = new MySqlParameter("?direction", MySqlDbType.VarChar, 50);
arParams[3].Direction = ParameterDirection.Input;
arParams[3].Value = direction;
return MySqlHelper.ExecuteReader(
GetReadConnectionString(),
sqlCommand.ToString(),
arParams);
}
}
, 내가 얻을 : 지금은 제목, 저자 또는 다른 속성으로이 책을 분류하려고, 난이 코드를 사용하고 있습니다 여기 exemple에 대한 제목으로 정렬 내 SqlCommand를하고 arParams : 나는 어떤 해결책을 찾지 못했습니다
{?PageSize} : 20 {?OffsetRows} : -20 {?Critere} title {?direction} DESC
이 도와주세요 : 는
{SELECT * FROM a_book ORDER BY ?Critere ?direction LIMIT ?PageSize ;}
arParams을하는 SqlCommand.
들으, 난 문자열 STR을 사용하여 고정 = "ORDER를에 의해"+ critere + ""+ 방향; sqlCommand.Append (str); 동일하게 : sqlCommand.AppendFormat ("ORDER BY {0} {1}", Critere, direction) 너무 감사드립니다. –