有时需要对数据库进行升序排列,或者降序排序,这里就需要用到desc与asc了。
desc:从大到小排列
asc:从小到大排列
写了个demo:
desc模式:
DBMysql dBMysql = new DBMysql();
dBMysql.ConnectDB("10.10.13.140", 3306, "root", "sa", "testdb");
string strSql = "select * from recordpiece order by id desc limit 10";
DataSet dt = new DataSet();
if(!dBMysql.SqlExe(strSql,ref dt))
{
Console.WriteLine("SupplyFreeBlock m_bFileFull = false error sql ={0}", strSql);
return;
}
int iSize = dt.Tables[0].Rows.Count;
for (int i = 0; i < iSize; i++)
{
var id = dt.Tables[0].Rows[i]["id"];
Console.WriteLine("id ={0}", id);
}
结果输出:
asc模式:
DBMysql dBMysql = new DBMysql();
dBMysql.ConnectDB("10.10.13.140", 3306, "root", "sa", "testdb");
string strSql = "select * from recordpiece order by id asc limit 10"; //desc
DataSet dt = new DataSet();
if(!dBMysql.SqlExe(strSql,ref dt))
{
Console.WriteLine("SupplyFreeBlock m_bFileFull = false error sql ={0}", strSql);
return;
}
int iSize = dt.Tables[0].Rows.Count;
for (int i = 0; i < iSize; i++)
{
var id = dt.Tables[0].Rows[i]["id"];
Console.WriteLine("id ={0}", id);
}
输出: