Return value of sql query to textbox in C# -


i want access last value in database column increment 1 , show on textbox used code nothing displayed on text box what's wrong code?

sqlcommand cmd = new sqlcommand("select (max[account_no]  addcustomer ", my);  int result = ((int)cmd.executescalar()); textbox1.text = result.tostring(); 

you can change sql statement below

select max(account_no) + 1 addcustomer

or increment after selecting value code

sqlcommand cmd = new sqlcommand("select max(account_no)  addcustomer ", my); int result = ((int)cmd.executescalar()) +1; 

final code :

try {     using (sqlconnection con = new sqlconnection(connectionstring))     using (sqlcommand cmd = new sqlcommand("select max(account_no) + 1 addcustomer", con))     {         con.open();         int result = (int)cmd.executescalar();         textbox1.text = result.tostring();     } } catch (sqlexception ex) {     messagebox.show(ex.tostring()); // exception here? } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -