以下のようにSQLステートメントを変更できます
SELECT MAX(Account_No) + 1 FROM addcustomer
またはコードで値を選択した後にインクリメントする
SqlCommand cmd = new SqlCommand("SELECT MAX(Account_No) FROM addcustomer ", my);
int result = ((int)cmd.ExecuteScalar()) +1;
最終コードは次のようになります。
try
{
using (SqlConnection con = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand("SELECT MAX(Account_No) + 1 FROM addcustomer", con))
{
con.Open();
int result = (int)cmd.ExecuteScalar();
textBox1.Text = result.ToString();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString()); // do you get any Exception here?
}