string was not in a correct format

0

I have this code to load a TextBox the last data of the Database and add 1 to carry a user count

private void generaidusuario()
    {
        string sql = @"SELECT TOP 1 Id_usuario FROM Tab_usuarios ORDER BY Id_usuario DESC";
        {
            SqlCommand command = new SqlCommand(sql, cn);
            cn.Open();
            string codmax = Convert.ToString(command.ExecuteScalar());
            int cod = Convert.ToInt32(codmax) + 1; //aqui me da error la conversion//
            txtidempleado.Text = Convert.ToString(cod);
            cn.Close();

        }
    }
    
asked by Samuel Ignacio Susana Confesor 09.12.2018 в 17:02
source

0 answers