Nomonom Nomonom - 6 months ago 23
SQL Question

OrderBy clause in C#

This is a method that gets data from a view in my database.

public static DataTable GetUnloadingPointList(string whereClause, string connectionString)
{
string strSql = @"SELECT * FROM view_ODW_SI_UnloadingPoints ";

if (!string.IsNullOrEmpty(whereClause))
{
strSql += "where " + whereClause;
}


What I am trying to do here is to add an
order by
clause by id. My export in excel is done from another method, but I need this one.

Answer

Try this one :

public static DataTable GetUnloadingPointList(string whereClause, string connectionString)
            {
                string strSql = @"SELECT * FROM view_ODW_SI_UnloadingPoints where 1=1 ";

                if (!string.IsNullOrEmpty(whereClause))
                {
                    strSql += " and  " + whereClause;
                }
                 strSql += " order by id  " ;