c# - SqlDataAdapter as Object value? -


hello guys have got sqldataadapter finds highest value:

datatable dt = new datatable();              sqldataadapter sda = new sqldataadapter("select max (id_k) klient", spojeni); sda.fill(dt);   spojeni.close(); 

if selects need result add +1 , insert object value parameter.

prikaz2.parameters.addwithvalue("@val4", ); // here should sda +1 

i tried insert object value whole sqldataadapter nonsense. there way achieve that?

thanks in advance

you can use sqlcommand.executescalar() method getting value because;

executes query, , returns first column of first row in result set returned query.

since command returns maximum value of id_k column, want.

sqlcommand command = new sqlcommand("select max (id_k) klient"); sqldataadapter sda = new sqldataadapter(command, spojeni); int max = (int)command.executescalar(); prikaz2.parameters.addwithvalue("@val4", max + 1); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -