Hello,
Maybe someone can tell me where is a mistake here. I'm taking dataes from MS SQL DB and put it into dropdownlist menu as items, but i need to sort them by ID. for example this code take data from table "Year" which has columns: YearID, Year:
for (int iCount = 1; iCount <= num_of_str; iCount++)
{
//create command object
SqlCommand cmdGetCalls = new SqlCommand("SELECT Year FROM Year WHERE YearID =" + iCount + "ORDER BY YearID DESC", sqlConnection);
//create reading data object
SqlDataReader dreadCalls;
//do a command
dreadCalls = cmdGetCalls.ExecuteReader();
//show strings
while (dreadCalls.Read())
{
ddlYear.Items.Add(new ListItem(dreadCalls.GetInt32(0).ToString(),dreadCalls.GetInt32(0).ToString()));
}
jCount++;
//close reading data object
dreadCalls.Close();
}
But this tale: "ORDER BY YearID DESC" doesn't work and i can not understand why.
Will be very thankful for any help!
Best regards,
Alexander
Maybe someone can tell me where is a mistake here. I'm taking dataes from MS SQL DB and put it into dropdownlist menu as items, but i need to sort them by ID. for example this code take data from table "Year" which has columns: YearID, Year:
for (int iCount = 1; iCount <= num_of_str; iCount++)
{
//create command object
SqlCommand cmdGetCalls = new SqlCommand("SELECT Year FROM Year WHERE YearID =" + iCount + "ORDER BY YearID DESC", sqlConnection);
//create reading data object
SqlDataReader dreadCalls;
//do a command
dreadCalls = cmdGetCalls.ExecuteReader();
//show strings
while (dreadCalls.Read())
{
ddlYear.Items.Add(new ListItem(dreadCalls.GetInt32(0).ToString(),dreadCalls.GetInt32(0).ToString()));
}
jCount++;
//close reading data object
dreadCalls.Close();
}
But this tale: "ORDER BY YearID DESC" doesn't work and i can not understand why.
Will be very thankful for any help!
Best regards,
Alexander