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
Post a Comment