Order sql table by descending order in C# -
since id column ordered asc order, want change ordering desc order. have following table
i'm using following code in order perform desc ordering, nothing happens in table.
private void button4_click(object sender, eventargs e) { string columnname = textbox9.text; try { using (sqlconnection cn = new sqlconnection(@"data source=(localdb)\v11.0;attachdbfilename=|datadirectory|\produkt.mdf;integrated security=true")) { cn.open(); using (sqlcommand command = new sqlcommand("select id, navn, varenr, antal, enhed, priseksklmoms, konto produkttable order [" + columnname + "] desc", cn)) { command.executenonquery(); } } } catch (exception ex) { messagebox.show("error\n" + ex.message, "error", messageboxbuttons.ok, messageboxicon.error); } }
i'm writing column name "id" in textbox9, , executenonquery method returns "-1" every time triggered. why doesn't table perform desired sorting ?.
thanks in advance
from sqlcommand.executenonquery
method
for update, insert, , delete statements, return value number of rows affected command. when trigger exists on table being inserted or updated, return value includes number of rows affected both insert or update operation , number of rows affected trigger or triggers. for other types of statements, return value -1. if rollback occurs, return value -1.
since use select
statement, so..
by way, should use parameterized queries. kind of string concatenations open sql injection attacks.
Comments
Post a Comment